next up previous contents index
Next: Declaring Degenerate Dimensions Up: Declarations Previous: Declarations

Scope Rules

 

Variables must be declared before they are used. Except for regions, which are dynamically scoped, ZPL uses two-level lexical scoping: Variables may be declared in the global scope or they may be declared within the scope of a procedure. Variables defined local to a procedure hide any global variables of the same name.

Variables are defined with the keyword var:

    var a : float;          -- declaration of a sequential variable
        A : [R] float;      -- declaration of a parallel array
Multiple variables may be declared using the same type specifier:
    var X, Y : [R] float;
Nested structures are declared from left to right. The following declares an indexed array of parallel arrays of float, that is, ten distinct parallel arrays of floats.

    var B : array [1..10] of [R] float;
By contrast, the following declares a parallel variable where each element consists of ten floating point numbers.

    var C : [R] array [1..10] of float;
Finally, the following example shows a parallel array where each element is a record:

    type complex = record
           r : float;
           z : float;
         end;

    var D : [R] complex;    -- parallel array of complex records



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