A single step may be as simple as ["get", "x"]
. This returns the Agent
's "x"
value to the outer step that contains it. So, for example, the step ["add", 1, ["get", "x"]]
, working from the inside out, retrieves the "x"
value and then adds 1
to it. More complex steps function similarly, always traversing to the deepest nested step, evaluating it, and 'unwrapping' until all steps have been executed.
A step's first element should be a string that is one of the allowed operators, followed by a certain number of arguments.
Operator | Arguments | Notes |
---|---|---|
"add" |
2 |
Pass 2 numbers, or two steps that evaluate to numbers |
"subtract" |
2 |
"" |
"multiply" |
2 |
"" |
"divide" |
2 |
"" |
"mod" |
2 |
"" |
"power" |
2 |
"" |
"get" |
1 |
Pass the key of Agent data to retrieve |
"set" |
2 |
Pass the key and value to set |
"enqueue" |
2 |
Pass the key and value to enqueue |
"local" |
2 |
Pass the key and value to set as local variables |
"if" |
3 |
Pass the conditional (usually a step that evaluates to a boolean), the step to run when true , and the step to run when `false |
"and" |
2 |
Pass the two steps to logically evaluate |
"or" |
2 |
"" |
"gt" |
2 |
"" |
"gte" |
2 |
"" |
"lt" |
2 |
"" |
"lte" |
2 |
"" |
"eq" |
2 |
"" |
"map" |
2 |
Pass an array (or step that evaluates to an array) and a lambda to invoke for each element |
"filter" |
2 |
"" |
"key" |
2 |
Pass an object (or step that evaluates to an object) and the key to retrieve from that object |
"agent" |
0 |
No arguments; returns the Agent |
"environment" |
0 |
No arguments, returns the Environment |
"vector" |
any |
Creates an n-dimensional Vector from the supplied arguments |
Points to the Environment
that is passed in the Rule
's constructor function (should be the same Environment
of the Agent
invoking this Rule
)
Generated using TypeDoc
The
Rule
class is an experimental interface for adding behavior toAgent
s. ARule
object may be used in place of atick
function to be added asAgent
behavior usingagent.set('tick', tickRule)
. As a trivial example, consider the followingRule
, which increments theAgent
'sx
value with every time step:Reading from the outer arrays inward, the steps of this
Rule
instructs theAgent
to:set
theAgent
's"x"
value to...add
ing1
and...Agent
's current"x"
valueGenerally,
Rule
steps are a deeply nested array, where the first value of any given array is always an instruction or operator (e.g."set"
,"add"
,"filter"
). See theconstructor
function for more information about steps.0.3.0