12.1.3 Element references
Collections in Dylan include such data structures as arrays, strings, lists, and tables. Each collection has a mapping from keys to elements. Dylan's syntax for referring to an element of a collection has two parts:
1. An operand whose value is the collection
2. An expression, in square brackets, whose value is the key that maps to the desired element of the collection
If the collection is a multidimensional array, the key expression in square brackets can be a series of expressions, separated by commas. Each expression yields the index for one dimension of the array. (Dylan array indices are zero based.)
The following example returns the first element of the array named by my-array:
my-array[0];
An element reference, like a slot reference, is an abbreviation for a function call. The generic function element takes a collection and a key as arguments, and returns the element of the collection that is associated with the given key. Except for the order of evaluation, the following examples are equivalent:
my-array[0]; element(my-array, 0);
For arrays of more than one dimension, the key expression in brackets is instead a comma-separated series of expressions. In this case, the element reference is an abbreviation for a call to the aref generic function. This function takes an array and any number of indices as arguments, and returns the element associated with the array indices. Except for the order of evaluation, the following examples are equivalent:
my-array[0, 2]; aref(my-array, 0, 2);




