START
<name> <(arguments)> <GLOBAL(arguments)> ;
language statements
FINISH
<name> ;
The START statement defines the beginning of a module definition. Subsequent statements are not executed immediately, but are instead parsed for later execution. The FINISH statement signals the end of a module definition.
The arguments to the START statement are as follows:
is the name of a user-defined module.
are names of variable arguments to the module. Arguments can be either input variables or output (returned) variables. Arguments listed in the GLOBAL clause are treated as global variables. Otherwise, the arguments are local.
are statements making up the body of the module.
If a parsing error occurs during module compilation, the module is not defined. See Chapter 6 for details.
The following example defines a function module that has one argument. It returns a matrix that is the same dimensions as the input argument. Each element of the output matrix is twice as large as the corresponding element of the input matrix:
start MyFunc(x); return(2*x); finish; c = {1 2, 3 4}; d = MyFunc(c); print d;
The next example defines a module subroutine that has two input arguments (A and B) and two output arguments (X and Y). Notice that the arguments sent into the module are changed by the module:
start MyMod(x, y, a, b); x = a + b; y = a - b; finish; a = 1:3; b = {1 0 -3}; run MyMod(p, q, a, b); print p, q;
The last example defines a module that has a GLOBAL clause. The global variables Z and W can be read and modified by the module:
start MyGlobal(a,b) global(z,w); z = a*w + b; finish; w = 1:4; call MyGlobal(2, 1); print z;