Class is a set of variables and functions which describe properties and behaviour of a turtle (object) in POOL.
It is a convenient way to organize a program which runs multiple turtles.
POOL uses the syntax of a function definition to define also a class. Body of the class-function contains code
which is executed when new turtle is created. This code includes definitions of member functions and variables.
Function which is used to define a class can be considered as a constructor of new turtle. Note:
this function should not output any value.
Most of multi-turtle programming tasks will need a way of communication between turtles in order to exchange
values of variables or mutually call member functions. POOL uses operator
@ for this purpose.
All member functions in POOL are public and can be called mutually by turtle-objects. Variables are:
- public, if they are defined as global; public variables can be read with
- protected, if they are defined as local; protected variables are not available for other turtles;
- static, if they are defined as shared; single instance of a shared variable is available for all turtles.
to model :p
make "l 0
to fn :x
make "l :x
make "t (list (newt $model 2) (newt $model 3) (newt $model 5))
foreach "z :t [(print who @ :z (fn repcount) @ :z)]
foreach "z :t [print :l @ :z]
[model1 model2 model3]
to model :h0 :c
rt :a fd :v
"a := :a + rnorm 2
if abs :a > 30 ["a := 30 * sign :a]
"v := :v + rnorm 0.1
if :v < 0 ["v := 0]
make "v 3
let "a 0
"n := 5
repeat :n [
"h := 360 * repcount / :n
"c := 1000 * repcount / :n
"t := (newt $model :h :c)
"ts := children
let "tick timer [
foreach "t :ts [step @ :t]
if :iter % 100 = 0 [
let "s 0
foreach "t :ts ["s := :s + :v @ :t]
print :s / count :ts
(program is drawing in the graphics window)
Function definition and call
Remote variables and results of remote calls.
Veriables, data access
Turtle - object
#, turtle - get the turtle
Function as a value
$, func - get the function
Table of Content