Chapter 3 The Application Description Language

3.9 Complex Data Types

Indexed Arrays

An indexed array is a complex data type derived from one of the base or compound types. All elements of an indexed array must be of the same type, but since lists can be array elements this restriction is not severe. Indexed arrays cannot be members of lists, but a handle to an indexed array can be such a member.

The type and dimensionality of an indexed array must be declared before its use, but indexed array bounds are not fixed. Indexed array indices must be integers, but need not be positive or even non-negative. An indexed array expands as it receives values assigned to new elements beyond the previous bounds. It is a run-time error to use the value of an indexed array element before that element receives an assignment. An indexed array element can be the target of an assignment and can appear in any expression where a constant or variable of its type is appropriate.

You can assign indexed arrays provided that the rvalue for the assignment is an array of the same dimensionality and type. A deep copy occurs in such a case, and all the previous data from the target array is lost. Indexed arrays can also appear with the relational operator (==) provided that both operands are indexed arrays. Two indexed arrays are considered equal if they possess the same dimensionality, the same type, the same bounds, the same assigned elements, and the corresponding elements are equal in each array.
Indexed Array Usage
Declaration
integer anInt;
integer twoDimArray<2>, anotherArray<2>;
list listArrayA<1>;
Element Assignment, Expression Use and Initialization Checking
twoDimArray[0,1] = 5;
anInt = twoDimArray[0,1] + 1;
anInt = twoDimArray[0,0]; // error, used before set
Array Assignment and Operations
anotherArray = twoDimArray;
if ( anotherArray == twoDimArray )
{ /* Do This */ }
anotherArray[0,0] = 1;

if ( anotherArray == twoDimArray )

{ /* Don't Do This */ }

Use arrays with caution because they require considerable storage over and above that required for their elements. The relation between indexed arrays and pointers in C and C++ does not hold between ADL's arrays and handles. In the ADL, you can pass the handle of an array as an argument to a built-in function or a message. Note that in this case the handle being passed points to the original array, not a copy of it

Associative Arrays

An associative array is a complex data type derived from one or more of the base or compound types. An associative array is similar to an indexed array except that the indices, or keys, need not be an integer but can be of any base or compound type, even a list. Certain index types, however, are probably not useful. For instance, a real index could be misleading.

All elements of a single associative array must possess keys of the same type. You declare the key and value types in the array declaration. As with indexed arrays, associative arrays are dynamic, growing as elements receive assignment. They can receive assignment as a unit, and their equality tested as such. Associative arrays are equal if and only if the values and keys of both arrays are of the same types, they possess the same keys, and elements with the same keys possess the same value.
Associative Array Usage
Declaration
string captionArray<integer>;
list authorArray<string>;

string holiday<string, integer>;

string key;

Element Assignment, Expression Use and Initialization Checking
captionArray[19774] = "The old covered bridge";
key = "Joseph Conrad";
authorArray[key] = { 'Nostromo, 'Victory, "Lord Jim" };

holiday[ 'July, 4 ] = "Independence Day";

Array Element Operators

There are two special unary operators that you can use with array elements or expressions that evaluate to array element lvalues.


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker