Repository navigation
Global functions #821
Replies: 2 comments 1 reply
|
Dear,
To call an function defined in the global, you (now) have to apply it on
the world agent (the agent instanciating the global) :
float this_result <- world.my_function (this_input);
Could you point out the page where your syntax is presented as OK, so we
can update the documentation.
Thank you in advance
Benoit
Le lun. 23 févr. 2026 à 00:16, Ric-Clarke ***@***.***> a
écrit :
… Apologies for the naive newbie question.
I'm trying to call a function defined in the global species from another
species, using the following pattern:
global {
...
float my_function (float some_input) {
float result;
// do the calculation
return result;
}
...
}
species some_regular_species {
init {
...
float this_input <- 1.5; // or whatever
float this_result <- my_function (this_input);
...
}
}
From the documentation, this should be OK but it doesn't run. I get a
validation error: "No operator found for applying 'my_function' to type
float".
Would appreciate assistance on what am I doing wrong.
—
Reply to this email directly, view it on GitHub
<#821>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3WSWW5ATTPRQD7BX372T4NI2GFAVCNFSM6AAAAACV4DMQKCVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZZGUYTSMJXHE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
1 reply
|
Dear,
Thank you a lot for your feedback !
I correct the first page you mentioned, to make it explicit to need to
prefix attribute by world.
About inheritance, keep in mind that all the species are *not* children (in
terms of inheritance) of the global species.
In particular, they do not inherit from some built-in attributes specific
to the global such as step.
They have a common parent species (defined in Java only).
Cheers
Benoit
Le mar. 24 févr. 2026 à 00:27, Ric-Clarke ***@***.***> a
écrit :
… Dear Benoit
Many thanks for your quick response. The syntax change solves the problem.
The pages that suggest that my original syntax should work are:
https://gama-platform.org/wiki/GlobalSpecies
"In the global species, you can define the attributes, actions, and
behaviors that describe the world agent. There is one unique world agent
per simulation: it is this agent that is created when a user runs an
experiment and that initializes the simulation through its init scope. The
global species is a species like others and can be manipulated as them. In
addition, the global species automatically inherits from several built-in
variables and actions. Note that a specificity of the global species is
that all its attributes can be referred by all agents of the simulation."
https://gama-platform.org/wiki/Inheritance
"As for many object-oriented programming languages, inheritance can be
used in GAML. It is used to structure better your code when you have some
complex models. It is, for example, useful when you have defined two
different species with many attributes and behaviors in common: you can
factorize everything in common in a parent species, and let in the child
species only the differences between these 2 species."
It is sugested that: "To make a species inherit from a mother species, you
have to add the facet parent, and specify the mother species."
I had assumed that all species are implicitly children of the Global
species, so there is no need for the parent facet.
When I asked chatgpt "gaml 2025 use a global function in a species", the
response was:
"In GAML 2025, you can call a global function inside a species exactly the
same way you would call it anywhere else — as long as the function is
defined in the global block."
The example code fragment it provides does not inclide the "world." prefix.
I trusted chatgpt - my mistake!
Regards,
Ric Clarke
School of Computing, Australian National University
—
Reply to this email directly, view it on GitHub
<#821 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3WSWBAFUSYFN7QLLYHVL4NOEFZAVCNFSM6AAAAACV4DMQKCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTKOJQGI3TMMQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Apologies for the naive newbie question.
I'm trying to call a function defined in the global species from another species, using the following pattern:
global {
...
float my_function (float some_input) {
float result;
// do the calculation
return result;
}
...
}
species some_regular_species {
init {
...
float this_input <- 1.5; // or whatever
float this_result <- my_function (this_input);
...
}
}
From the documentation, this should be OK but it doesn't run. I get a validation error: "No operator found for applying 'my_function' to type float".
Would appreciate assistance on what am I doing wrong.
All reactions