Next: , Previous: , Up: Statements   [Contents][Index]

7.12 Subroutine Definition

A subroutine is a named "black box" that performs a specific task. The user interacts with the subroutine through the subroutine’s parameters, and possibly through global variables (Global Variables).

LUX offers many built-in subroutines (Internal Routines), and also allows you to define your own in the LUX language, with a subroutine definition statement. All variables that are used inside such a definition are local to the routine (Local Variables), except for those variables whose names start with one of the characters ! # $, which are global (Global Variables).

SUBR name [ , par1, par2, … ]
[ statement2
  … ]

This defines a subroutine called name, with parameters par1, par2, etcetera. The subroutine consists of the statements statement1, statement2, etcetera, which use the parameters to determine what needs to be done.

A special method is available for allowing arbitrary numbers of variables. It is selected by adding a triple period (...) as the last parameter of the subroutine, and then if any arguments fall beyond the last regular one, then the last regular parameter is changed into a cplist variable and its previous value and all subsequent ones are entered into the list in the order in which they are specified. An argument list that ends with ... is referred to as an extended parameter list.

See also: Subroutine Call, Extended Parameter Lists