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  ;function-constructor of the "model" class
  make "l 0      ;global variable - accessible publicly
  to fn [:x 2]   ;member function definition
    make "l :x      ;store the argument value in :l
    output :x^:p    ;result: argument to the power :p
  end
end

;single turtle of the "model" class
make "t (newt $model 2)

print who @ :t     ;instruction call
print (fn 5) @ :t  ;function call with an argument
print fn @ :t      ;function call without argument
print :l @ :t      ;reading the value of variable

Output:

model1
25
4
2

Example 2:

to model ;class definition
  make "l random 5
  to fn :p
    output :l^:p
  end
end

;three turtles of the "model" class
make "t newturtles 3 $model

print who @ :t     ;instruction call
print :l @ :t      ;reading the value of variable
print (fn 5) @ :t  ;function call with an argument

Output:

[model1 model2 model3]
[1 4 0]
[1 1024 0]

See also:

Żółw - obiekt
Równolegle działające żółwie

Table of Content