New turtle (asynchronous constructor)
(anewturtle)
anewturtle [instructions]
(anewturtle [instructions] expr1 expr2 ...)
anewturtle function
(anewturtle function expr1 expr2 ...)
(anewt)
anewt [instructions]
(anewt [instructions] expr1 expr2 ...)
anewt function
(anewt function expr1 expr2 ...)
Creates new turtle. A list of instructions or a function passed as an argument is used as
constructor of the new turtle. The constructor is executed in parallel to subsequent instructions of the turtle
which called anewturtle
instruction. The constructor's arguments can be
passed as optional expressions.
Example 1:
"t := (anewt)
print who
print children
print parent @ :t
print who @ :t
Output:
first
[t1]
first
t1
Example 2:
"t := anewt [
"x := 10
print who
]
print who
Output:
Note: the message "first" may appear before "t1". The constructor is executed in parallel to
instructions of the turtle #first
.
first
t1
Example 3:
to model :x
to fn
op :variable^2
end
wait 50
let "variable :x
print who
end
"t := (anewt $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 finish.
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
Table of Content