Go to the first, previous, next, last section, table of contents.

Array Constructor

<arr type> "{" <expr1> "," ... "," <exprn> [ ", .." ] "}"

An array constructor is an array-valued expression. <arr type> must be a fixed or open array type (see section Array Types). Each <expr> must be assignable to the element type of A. Thus, multidimensional array constructors are built by nesting array constructors (see tictactoe example below). For fixed array constructors, there must be one expression per slot, with the shortcut that if ", .." is included at the end, the last expression is repeated as many times as is needed to fill out the array.

In some of the examples below, the type of the constant or variable is explicitly specified apart from the constructor. In others, the constructor itself provides the type. Either case is valid (except when an open array type is used as a constructor).

CONST
  vowels: ARRAY [1..5] OF CHAR =
             ARRAY [1..5] OF CHAR{'a','e','i','o','u'};

  names = ARRAY [1..10] OF TEXT{"John", "Suzie", "Helen", "", ..}; 
              (* names[4] thru names[10] are set to empty strings *)

  invalid = ARRAY [1..20] OF INTEGER{5, 10, 15};
              (* not enough elements provided *)

VAR
  openarr := ARRAY OF CHAR{'a', 'b', 'c'};
              (* invalid: a variable may not be an open array *)

  vowels2: ARRAY [1..5] OF CHAR := ARRAY OF CHAR{'a','e','i','o','u'};
              (* But an open array constructor can be assigned to a 
                 fixed array type *)

  tictactoe := ARRAY [1..3], [1..3] OF CHAR{
                  ARRAY OF CHAR{' ', ' ', ' '},
                  ARRAY OF CHAR{' ', ' ', ' '},
                  ARRAY OF CHAR{' ', ' ', ' '} 
               };


Go to the first, previous, next, last section, table of contents.