Array Variable

Array indices are positive 32 bit integers. You can declare arrays with multiple dimensions.

   Row[ 1 to 10 ]  byte        :10 Byte elements indexed 1 to 10
   Row[ 99 ]       string      :100 String elements indexed from 0 to 99.
   Matrix[ 3, 4 ]  double      :20 Double precision elements in a 3 x 4 array.

Array bounds can also be enumerated.

   Shade[ Color{ .blue }]       byte   :0 ip to the color blue.
   Shade[ 1 to Color{ .blue }]  byte   :First color up to the color blue.
   Shade[ Color{ * }]           byte   :0 up to the highest enumerated color.

The lower bound is always constant and may be a constant expression. You can declare variable sizes for the upper bound for dynamic arrays and in procedure parameters.

You can declare an array with a parameterized size as a local value in a procedure. The upper bound can be an expression composed with input paramters and constants. The lower bound must still be a constant expression.

   function OPERATE               :Start of a procedure
    entry Max     word            :Input parameter used to size the array
     exit Result  string          :The function result is a String.

    local Value[ Max ]  string    :A dynamic array with Max + 1 elements

Declaring variable sized arrays in procedure parameters is done by specifying the upper bound as a variable name with a leading star. The variable is a passes into the procedure as a Word parameter. You reference the bound in the procedure by the name. When you pass in the array on a procedure call the value of the array bound is implicitly passed.

   function SUM
    entry Array[ *Max ]  double       :Variable upper bound
     exit Sum            double

   DO I = 0 to Max                    :Traverse the array range.
      Sum += Array[I]                 :Sum each element.
   -

   return

If the bound variable is never referenced in the procedure, omit the name and just code a star. This example could also be written more simply as:

   function SUM
    entry Array[*]  double            :Variable upper bound with no name
     exit Sum       double

   DO @Element in Array               :Point at each element in the array.
      Sum += Element                  :Sum each element.
   -

   return

Enumeration and Structure

Arithmetic Expression