[top] [prev] [next]

Array types

An array is an indexed collection of component variables, called the elements of the array. The indexes are the values of an ordinal type, called the index type of the array. The elements all have the same size and the same type, called the element type of the array.

There are two kinds of array types, fixed and open. The length of a fixed array is determined at compile time. The length of an open array type is determined at runtime, when it is allocated or bound. The length cannot be changed thereafter.

The shape of a multi-dimensional array is the sequence of its lengths in each dimension. More precisely, the shape of an array is its length followed by the shape of any of its elements; the shape of a non-array is the empty sequence.

Arrays are assignable if they have the same element type and shape. If either the source or target of the assignment is an open array, a runtime shape check is required.

A fixed array type declaration has the form:

    TYPE T = ARRAY Index OF Element
where Index is an ordinal type and Element is any type other than an open array type. The values of type T are arrays whose element type is Element and whose length is the number of elements of the type Index.

If a has type T, then a[i] designates the element of a whose position corresponds to the position of i in Index. For example, consider the declarations:

    VAR a := ARRAY [1..3] OF REAL {1.0, 2.0, 3.0};
    VAR b: ARRAY [-1..1] OF REAL := a;
Now a = b is TRUE; yet a[1] = 1.0 while b[1] = 3.0. The interpretation of indexes is determined by an array's type, not its value; the assignment b := a changes b's value, not its type. (This example uses variable initialization, and array constructors.)

An expression of the form:

    ARRAY Index_1, ..., Index_n OF Element
is shorthand for:
    ARRAY Index_1 OF ... OF ARRAY Index_n OF Element

This shorthand is eliminated from the expanded type definition used to define structural equivalence. An expression of the form a[i_1, ..., i_n] is shorthand for a[i_1]...[i_n].

An open array type declaration has the form:

    TYPE T = ARRAY OF Element
where Element is any type. The values of T are arrays whose element type is Element and whose length is arbitrary. The index type of an open array is the INTEGER subrange [0..n-1], where n is the length of the array.

An open array type can be used only as the type of a formal parameter, the referent of a reference type, the element type of another open array type, or as the type in an array constructor.

Examples of array types:

    TYPE
       Transform = ARRAY [1..3], [1..3] OF REAL;
       Vector    = ARRAY OF REAL;
       SkipTable = ARRAY CHAR OF INTEGER

[top] [prev] [next]