next up previous contents index
Next: Value-returning Procedures. Up: Statements Previous: Caveats

Procedures

   

ZPL provides procedures that are similar to those available in other imperative languages. Procedures can be prototyped, defined, and invoked.

   

A prototype defines a procedure's interface by specifying the procedure's name, the names and types of any parameters, and the type of any return value. Prototypes allow the programmer to specify the type of a procedure before it is defined, which is useful in allowing separate compilation (which is currently not supported by the ZPL compiler) and in allowing mutually recursive procedure calls. A prototype is syntactically identified by the keyword prototype. In the example below, the max() procedure is declared to have two parameters of type integer and to return a value of type integer.

    prototype max (first: integer; second: integer): integer;

   

A procedure definition is similar to a prototype in that it defines the procedure's interface, but it also defines the body of the procedure. The interface specification is identical to a prototype but uses the keyword procedure instead of prototype. The body of a procedure is any ZPL statement (or compound statement). If a prototype is given for a procedure, the procedure's definition and prototype must agree in the types (but not names) of the parameters and return value.

   

By default, procedure calls in ZPL pass parameters by value. To pass a parameter by reference, the interface should include the keyword var. For example, as defined by the following prototype, the ZPLCheckTimer() procedure, passes both of its parameters by reference so that they may be modified by the procedure invocation.

    prototype ZPLCheckTimer (var sec: integer; var usec: integer);

ZPL uses lexical scoping except for regions, which are dynamically scoped. Each parallel statement must reside in the scope of a region of the appropriate rank. The body of a procedure may explicitly specify regions for its statements, but if a region of the appropriate rank is not explicitly specified, the scope of the call site is used. This dynamic scoping is the motivation for rank-defined parallel arrays in which the rank of an array parameter (or local array variable) is specified but not its precise bounds. This allows a single procedure to be invoked in the context of multiple regions. For example, a procedure that initializes some parallel arrays could be invoked as follows.

    [R]         Init();
    [east of R] Init();
    [west of R] Init();




next up previous contents index
Next: Value-returning Procedures. Up: Statements Previous: Caveats

Kay Nettle
Fri Feb 21 21:14:29 CST 1997