Language Reference


START Statement

  • 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:

name

is the name of a user-defined module.

arguments

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.

language statements

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;

Figure 24.394: A Function Module

d
2 4
6 8



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;

Figure 24.395: A Module Subroutine

p
2 2 0

q
0 2 6



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;

Figure 24.396: Results of Calling a Module with a GLOBAL Statement

z
3 5 7 9