Function name(param, param, Optional param, rest())
   commands
 EndFunction

Define a function. The function can take parameters. The names of these parameters are specified in parentheses after the function name.

If one parameter is preceded by Optional, all parameters following it are optional and can be omitted by the caller. They will report EMPTY when read.

The last parameter can be followed by (). This allows the caller to specify any number of values (including none at all) for this parameter, which will be packed into an array (making this a "varargs function", for C programmers).

A function can be called from expressions, by writing its name followed by parameters in parentheses. It will be called when the expression is evaluated, and its Return value be inserted into the expression.

 Function twice(a)
   Return 2*a
 EndSub
 Print twice(17)      % prints 34

Note that if a function takes no parameters, an empty pair of parentheses must still be specified (func()) to call the function.

If there already is a subroutine or function with the same name as this function, it will be replaced by the new definition.

Since: PCC2 1.99.9

See also: Sub, Elementary Commands

This is a testing version.
It may be incomplete, and have more bugs (or features) than the public live version at planetscentral.com.