Submitted by Phaul on Tue, 2006-09-05 13:34.

Functions declared with the func keyword. The function is callable in the scope where it was declared, starting from the end of the declaration, till the end of the scope. Subscopes could have functions or variables with the same name, in this case the inner function or variable overlaps the outer one. (see variables) The `(', `)' marks are always obligatory indicating the beginning and the end of the parameter list, no matter if the parameter list was empty. The parameters are taken by their position, and they are in-only parameters, the modification of their value will be lost. The result of the function is the value of it's last expression, just as it were a progn.

; the minimum
(func MIN (a b)
   (if (< a b) a b)

Note that a function can use - or even modify - the variables declared in it's outer scope, but not the variables of the calling scope.

Can you figure out the output?

(declare magic)
(set magic 2)
(func myfunc (a) (* magic a))

   (declare magic)
   (set magic 3)
   (print (myfunc 1))