6.1.1 Array Types

In Sisal, as in other languages, arrays are collections of elements of homogeneous types. In Fortran, for example, an array type is specified by the number of dimensions it has, and by its static size at compile-time. An array defined to be of size 100 by 50 can never change size or shape. In Sisal, the number of dimensions an array contains is specified by its type, but its sizes in each dimension are completely dynamic. But let's take this in small steps; consider the Sisal type declarations shown below.

type float = double_real;
type One_Dim_R = array [ float ];
type One_Dim_I = array [ integer ];
type Two_Dim_I = array [ One_Dim_I ];
The first statement defines a convenient type-name, "float", by which to refer to values of type double_real. The second defines a convenient type-name for an array whose elements are of type float. The third line specifies a type that is an array of integer elements, and the fourth line specifies an array of elements which are themselves one-dimensional arrays; this fourth type is an example of what we mean by a two-dimensional array in Sisal.

Note that in the array type declarations, no sizes are specified; this is because size and index range are not characteristics of array types, but only of specific values which are instances of array types. Arrays of type One_Dim_R can have as many elements as desired in the program; they can also have any index range the programmer finds expedient, as long as the upper index bound is at least as large as the lower bound. The same is true for arrays of type Two_Dim_I. Furthermore, the one-dimensional arrays making up the rows of a two-dimensional array can all have different sizes and index ranges, leading to what are called "ragged arrays".

These matters will be made clearer in the examples to follow. For the moment, the key point to focus on is that all values are dynamic and transitory in Sisal programs. If a statement returns, or evaluates to, a value that is a one-dimensional array, that array's size and index range are defined solely by the statement whose value it is; and, the value itself exists only until it is finally consumed by a further statement in the program.

One other matter concerning arrays should be mentioned at this time: indexing and logical structure. We have just seen that a two-dimensional array may be considered an array of one-dimensional arrays. This inductive hierarchical structuring continues into greater numbers of dimensions; for instance, a three-dimensional array is an array of two-dimensional arrays. When indexing an array, the elements accessed get smaller (or simpler) as more indices are specified from left to right. For instance, if we have the type declarations shown above, and array A is of type Two_Dim_I, then A[6] is the sixth row of A, and A[4,7] is the seventh element of the fourth row. It is also correct syntax to specify this element as A[4][7], which clarifies thae fact that we are specifying the seventh element of the fourth element of A.

There is no notation in Sisal for specifying a single column of a two-dimensional array, nor is there a correct notation for omitting the left or middle index from an access to a three dimensional array. Indices must be supplied from the left and omitted, if they are not all supplied, from the right.

Similarly, suppose we add the following declaration to the above set:

type Three_Dim_I = array [ Two_Dim_I ];
And suppose we have an array B of type Three_Dim_I. If we index as B[i], we are specifying the two-dimensional array formed by all the i-th rows of each plane. The B[i,j]-th element is the row of all the elements from row i, column j, in each plane. This indexing treatment is termed "row_major," and means that in walking through an array of any dimensionality, the leftmost array index varies fastest and the rightmost varies slowest. This is consistent with the indexing conventions found in the C language but not the same as in Fortran.

Previous Section



Next Section



Table of Contents