ZPL's ability to manipulate arrays as whole entities is intended to simplify the task of writing parallel programs by increasing readability and decreasing the likelihood of error. ZPL provides similar features for indexed arrays in the form of absent array references ([]), which are used to refer to an entire dimension of an indexed array. For example, the following statement assigns all elements of b to corresponding elements of a, where a and b are assumed to be 2D indexed arrays with the same dimensions.
a[][] := b[][]; -- aggregate assignment allowed for indexed arrays
Aggregate operations are provided for indexed arrays that allow them to be treated as whole entities. These are the assignment statements (see Table 6) and the binary operators (see Section 5.3).
For example, the following is legal, where the empty brackets represent all of the indices of a dimension.
var a, b : array [1..10, 1..5] of float; c : float; a[] := b[]; -- aggregate assignment allowed for indexed arraysFurthermore, whole indexed arrays can be used as operands to scan and reduce operators and in the wrap and reflect statements (Section 7.3 describes wrap and reflect) if these indexed arrays appear in parallel variables.
A single element of an indexed array can be specified or an entire indexed array can be specified, but there is no way to specify a sub-portion of an indexed array. This ``all or nothing'' rule applies to each individual indexed array, and is illustrated below using the following declarations:
type array1 = array[1..10] of integer; array2 = array[1..5] of array1; var a, b : array1; c : array2; a[] := b[]; -- refers to all elements of 'a' and 'b' a[] := c[1]; -- refers to all elements of 'a' and one element of 'c'
A more complicated example is shown below using the following declarations:
direction east = [0,1]; region R = [1..n, 1..n]; var a, b : array [6..10] of [R] array [1..5] of float;
The following two statements manipulate an indexed array of parallel arrays of indexed arrays as a single entity.
a[][] := b[][]; a[]@east[] := b[]@east[];The statement below refers to the entire outermost indexed array but only a single element of the inner indexed array; this is possible because the use of the @ operator explicitly differentiates the indices of the outer indexed array from those of the inner nested array.
a[]@east[1] := b[]@east[1];As with operations on parallel arrays, there are restrictions placed on aggregate indexed array operations to ensure compatibility of operands. Each array access in the r-value must have the same number of empty brackets as the l-value or no empty brackets at all. An exception is the use of scalars, which are promoted to an indexed array as with promotion to parallel arrays.