Replies: 0 comments 4 replies
-
Dear,
Here are some answers/remarks/comments on your 3 points:
*Point 1: ambiguity between species and population*
*In some certain cases, the variable types can be a little tricky, while
lacking documentation.*
*For example, when using species declaration names as action arguments to
access all agents, it is possible to use either of the following
combinations.*
*species Foo {}
action test_action(species<agent> foo) {}
do test_action(Foo);
action test_action_2(container<agent> foo) {}
do test_action_2(Foo.population);
do test_action_2(Foo);
action test_action_3(list<agent> foo) {}
do test_action_3(list(Foo));*
Pay attention to the fact that in all these actions, foo is not of the same
type.
My advise:
1) If you want to define an action in which you want to create agents of
a species given as parameter, choose the first action (foo in the
test_action is a species):
*action* test_action(*species<agent>* foo) {
*create* *foo*;
*write* *foo*;
*write* *list*(*foo*);
}
*reflex* toto {
*do* *test_action*(*Foo*);
}
2) If you want to use the list of all the agents of a species, use the
last one:
*action* test_action_3(*list<Foo>* foo) {*write* *foo*;}
*reflex* toto {
*do* *test_action_3*(*list*(*Foo*));
*do* *test_action_3*(*Foo* *as* *list*);
}
*Point 2: scope in the create statement:*
The documentation of the statement indeed makes it explicit that create
behaves as an ask. I admit the word scope could introduce in the doc in
order to make more explicit.
https://gama-platform.org/wiki/Statements#create
- If one wants to specify a special initialization sequence for the
agents created, create provides the same possibilities as ask. This
extended syntax is:
create a_species number: an_int {
[statements]
}
- The same rules as in ask apply. The only difference is that, for the
agents created, the assignments of variables will bypass the initialization
defined in species. For instance:
create species(self) number: rnd (4) returns: children {
set location <- myself.location + {rnd (2), rnd (2)}; // tells
the children to be initially located close to me
set parent <- myself; // tells the children that their parent is
me (provided the variable parent is declared in this species)
}
*Point 3: documentation of the create statement:*
*And ps. The algolia of the documentation site is just below the bars of
smartness I guess, for example when I search for create, I do not get the
statement page in the results.*
Even if it is not the first result, the statement page appears in the
results...
And all the other results are perfectly coherent with a search with the
"create" word.
[image: Screenshot 2022-07-15 at 11.41.23.png]
Being more precise with "create statement", the first result is the one
expected.
[image: Screenshot 2022-07-15 at 11.43.38.png]
Do not hesitate to send feedback and proposal on how to improve the
documentation.
Cheers
Benoit
Le jeu. 14 juil. 2022 à 06:37, DotIN13 ***@***.***> a écrit :
… In some certain cases, the variable types can be a little tricky, while
lacking documentation.
For example, when using species declaration names as action arguments to
access all agents, it is possible to use either of the following
combinations.
species Foo {}
action test_action(species<agent> foo) {}do test_action(Foo);
action test_action_2(container<agent> foo) {}do test_action_2(Foo.population);do test_action_2(Foo);
action test_action_3(list<agent> foo) {}do test_action_3(list(Foo));
And when creating agents, the scope actually shift to the species of
craetion as if in an ask block, which might cause unexpected shadowing.
species Foo {
int bar <- 0;
}
species Baz {
int bar <- 1;
create Foo number: 1 {
write bar;
write myself.bar;
}
}
// => 0// 1
This might be already in the documentation, but I just wanted to spin it
out here and hope it helps someone who also get confused with these scoping
and typing issues.
And ps. The algolia of the documentation site is just below the bars of
smartness I guess, for example when I search for create, I do not get the
statement page in the results.
—
Reply to this email directly, view it on GitHub
<https://github.com/gama-platform/gama/discussions/3464>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3WSXK5PNVFKFDJXG3KB3VT6KQRANCNFSM53Q4DRZQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In some certain cases, the variable types can be a little tricky.
For example, when using species declaration names as action arguments to access all agents, it is possible to use either of the following combinations.
And when creating agents, the scope actually shift to the species of craetion as if in an
ask
block, which might cause unexpected shadowing.This might be already in the documentation, but I just wanted to spin it out here and hope it will help people!
And ps. The algolia of the documentation site is just below the bars of smartness I guess, for example when I search for
create
, I do not get the statement page in the results.Beta Was this translation helpful? Give feedback.
All reactions