Global variables
Global variables are accessible in all functions (nested and parent w.r.t function that created a variable),
of a turtle. Note: all code out of any function is actually a body of the #first
turtle's main function.
Turtles in POOL are executing their tasks concurrently, and each turtle has its own set of global and local
variables. Turtles can read global variables of other turtles with use of @
operator. Global variables
are equivalent to public variables known in other programming languages.
Example:
to class :a :b
let "priv :a + :b
make "s2 :priv^2
to get_s
op :priv
end
to set_s :s
make "priv :s
make "s2 :s^2
end
end
make "t (newt $class 2 3)
print get_s @ :t
print :s2 @ :t
(set_s 6) @ :t
print get_s @ :t
print :s2 @ :t
Output:
5
25
6
36
Zobacz także:
Data types
Variables, data access
Table of Content