Function

func name
$name

Returns funkction with given name as a value. Functions in POOL are virtual and may be overriden in derived classes or by nested definitions. Function returned by func is always the same which would be used with a regular call to a function in this place in the code. Once function is obtained with func it is not overriden by later definitions.
In analogy to instruction thing, there is single-character synonim of func: $ which requires constant name of a function.

Example 1:

to ftest :x       ;simple definition
  output 2 * :x
end

to in_box
  to ftest :x     ;nested definition
    output :x / 2
  end

  print "in_box
  print (call :f 5) ;call to a function stored in the variable :f
  print ftest 5     ;this call uses the nested function
end

make "f $ftest    ;function stored in the variable :f
print (call :f 5) ;call to a function stored in the variable :f
print ftest 5     ;this call uses the simple definition of the function
in_box

Output:

10
10
in_box
10
2.5

Example 2:

Function model used as a constructor of turtles.

to model
  setxy (rnorm 0 100) (rnorm 0 50)
  seth random 360
  (setpc random 1000 random 60)
  setps 40
  pd fd 40
end

ht pu
make "t newturtles 20 $model

Output: drawing in the graphics window.

See also:

Function as a value

Table of Content