Sub name(param, param, Optional param, rest())
   commands
 EndSub

Define a subroutine. The subroutine can take parameters. The names of these parameters are specified in parentheses after the subroutine 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 subroutine", for C programmers).

A subroutine can be called by listing its name, followed by the parameters:

 Sub test(a)
   Print a
 EndSub
 test "hello, world"

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

See also: Function, Elementary Commands