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


7.15 Function Definition

A function is a named "black box" that returns a value. The user interacts with the function through the function’s parameters, and possibly through global variables (Global Variables).

LUX offers many built-in functions (Internal Routines), and also allows you to define your own in the LUX language, with a function definition statement.

FUNC name [ , par1, par2, … ]
  statement1
[ statement2
  … ]
ENDFUNC

This defines a function called name, with parameters par1, par2, etcetera. The function consists of the statements statement1, statement2, etcetera, which use the parameters to determine what needs to be done. A function must return a value, and to this end at least one return statement must appear in each function definition. A return statement in a function definition looks like this:

RETURN, value

The value value is what the function call returns. See Function Call for the use of a function.

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.

See Extended Parameter Lists for more details.