next up previous contents index
Next: Anonymous arrays Up: Arrays Previous: Arrays

Array declaration

The DJFieldDeclarator for an array takes one of the following four forms:
       Identifier DimExprs                   (1)
       Identifier DimExprs in D              (2)
       Identifier DimExprs R Exp             (3)
       Identifier DimExprs ConstrBlocks      (4)
where DimExprs and ConstrBlocks are defined as follow:
       DimExprs:              '['Expression ']'...'['Expression']'
       ConstrBlocks:          ConstrBlock | 
                              '{' ConstrBlocks, ..., ConstrBlocks '}'
       ConstrBlock:           '{' Constraint; ...,; Constraint '}'
(1) declares an array and impose no constraints on the elements; (2) says that for each element X in the array, X in D holds; (3) says that for each element X in the array, X R Exp holds; (4) imposes the constraints to the array elements as follows: Let A be the identifier of the array. When there is only one constraint block following DimExprs, the constraints apply to all the array elements. In contrast, when there a sequence of constraint blocks {B0, ..., Bn-1} following DimExprs (in this case, the size of the first dimension of the array must be equal to n), then Bi recursively applies to A[i] for i=0,...,n-1.

The following shows three examples:

       dj Button bts[10]{width == 30; height==30};
       dj Label lbs[3]{{text == "zero"},
                       {text == "one"},
                       {text == "two"}};
       dj int qs[10] in 0..9;
The first declaration declares ten buttons bts[0],...,bts[9] that have the same size $30\times 30$. The constraints width == 30; height==30 apply to all the ten buttons. The second declaration declares three labels, with the first label's text being "zero", the second being "one", and the third being "two". The last one declares ten attribute variables in the domain of 0..9.

Elements of component and attribute arrays can be referenced in the same way as array elements in Java.


next up previous contents index
Next: Anonymous arrays Up: Arrays Previous: Arrays
Neng-Fa Zhou
1999-02-16