New object (asynchronous constructor)
(newobject)
anewobject [instructions]
(anewobject [instructions] expr1 expr2 ...)
anewobject function
(anewobject function expr1 expr2 ...)
(newo)
anewo [instructions]
(anewo [instructions] expr1 expr2 ...)
anewo function
(anewo function expr1 expr2 ...)
Creates new object. A list of instructions or a function passed as an argument is used as
constructor of the new object. The constructor is executed in parallel to subsequent instructions of the turtle/object
which called anewobject
instruction. The constructor's arguments can be
passed as optional expressions.
Object in POOL is a simplified version of a turtle. Objects do not have graphics representation and do not
handle events related to graphics (e.g. mouse clicks). Objects use less memory, they are created faster and
also execute their tasks faster than turtles.
Example 1:
"t := (newo)
print who
print children
print parent @ :t
print who @ :t
Output:
first
[o1]
first
o1
Example 2:
"t := newo [
"x := 10
print who
]
print :x @ :t
Output:
Note: the message "first" may appear before "o1". The constructor is executed in parallel to
instructions of the turtle #first
.
first
o1
Example 3:
to model :x
to fn
op :variable^2
end
wait 50
let "variable :x
print who
end
"t := (anewo $model 5)
"y := fn @ :t
print who
Output:
Version 1: the message "first" appears always on top - turtle #first
is not waiting for the constructor.
first
model1
Version 2: the message "first 25" appears after "model1" - access to the fn
output
written in variable :y
makes the turtle #first
is waiting until the constructor is finished and the function is completed.
model1
first 25
See also:
Turtle - object
Synchronization of multiple objects
Table of Content