Access to class members
Single object
:variable @ turtle
instruction @ turtle
(instruction arg1 arg2 ...) @ turtle
Multiple objects
:variable @ collection
instruction @ collection
(instruction arg1 arg2 ...) @ collection
Turtle (an object) contains variables and functions defined by a class of the turtle.
Operator @
allows other turtles to access values of variables (note: only
global variables can be accessed in this way). Other turtles can also
launch functions and instructions of the turtle with use of the operator @
.
If the collection is used as a right-hand argument of @
operator, then the operation
(access to the variable, the instruction or function call) is executed for each of turtles
in the collection (note: all items of the collection have to be turtles or nested collections of
turtles).
If the operation returns a result, then it is inserted into a list or array of results, according to the type of
the collection used as the operator's argument. The order of result is the same as the order of turtles
in the input collection.
Operations of all turtles are executed in parallel. Before the operation is completed, the result is available
in the output collection as a promise.
Example 1:
to model :p
make "l 0
to fn [:x 2]
make "l :x
output :x^:p
end
end
make "t (newt $model 2)
print who @ :t
print (fn 5) @ :t
print fn @ :t
print :l @ :t
Output:
model1
25
4
2
Example 2:
to model
make "l random 5
to fn :p
output :l^:p
end
end
make "t newturtles 3 $model
print who @ :t
print :l @ :t
print (fn 5) @ :t
Output:
[model1 model2 model3]
[1 4 0]
[1 1024 0]
See also:
Żółw - obiekt
Równolegle działające żółwie
Table of Content