Set or create local variable
let name value
localmake name value
Stores the value in the local variable with the name, or creates a new local variable, if
there is no variable with the name among local variables created in the current function.
let is a shorter synonym used in POOL for the traditional
The example shows how local and global variables are accessed: the global variable
with the value
1 is accessible inside the function up to the moment when the local variable with the
same name and the value of
5 is created. Changes made to the value of the local variable do not
affect the global variable.
let "x 5
make "x 1
This example illustrates how local variables are created and how they can hide variables in the external scope.
factorial is recursive, it calls itself simultaneously decreasing value of the argument,
Function argument is always created as a new local variable in a function scope. It hides all variables with
the same name in external functions, including global and shared variables.
let "i :i + 1
creates the new local variable for each call to the function
factorial, including nested calls.
To calculate the initial value of the new variable,
:i is used
and its value is taken from the external function before the new variable is created. The external function can
factorial or main function of the
Value of the variable in the external function remains unchanged.
make "i :i + 1
assigns the new value to the variable
:i for each call to the
factorial. The new value of
:i is calculated
from its previous value. Value of the variable
in the main function of the
#first turtle is changed.
to factorial :x
let "i :i + 1
if :x > 1 [op :x * factorial :x - 1]
let "i 0
print factorial 5
Output (version 1):
Output (version 2):
Variables in POOL
make, name - set or create global variable
Table of Content