Get value of a variable

thing name
:name

Returns value of a variable with the specified name. Accessing variables is a very frequent operation in programming, therefore thing has also an abbreviated form: :. Note, that there is an important rule in POOL:

The thing instruction can take at the input any expression which outputs a word. This instruction should be used when the name of a variable is not known a priori, e.g. it is a result of function or a value of another variable. The abbreviated form : can be used only with a constant word provided in the source code.
In most cases names of variables are known constants. Then the short syntax with the colon is convenient and also the compiler can generate optimized code.

Variables in various scopes can have the same name. In this situation the variable which is accessed is selected in the following way: local variables are searched for the specified name, then global variables, and shared variables at the end.

Example 1:

make "x 12.3
print :x
print 2 * :x

Output:

12.3
24.6

Example 2:

make "l [a b c]
foreach "n :l [make :n repcount]
foreach "n :l [print thing :n]

Output:

1
2
3

See also:

Local, global, and shared variables

let, localmake - set or create local variable
make, name - set or create global variable

Table of Content