Go to the first, previous, next, last section, table of contents.


Array indexing

array_reference:
          expression `[' tuple_elements `]'
        ;

The array_reference rule allows array indexing to be done in TOM in a way familiar to many (C) programmers. Actually, the expression a[b] is a short-hand for [a at b]; when used as the lhs of an assignment, an array reference results in the invocation of the method set at: a[b] = c is equal to [a set c at b].

Note that the type of the index is not restricted to be integer; it can be anything. For example, a dictionary mapping objects to objects could implement a method

Any at All key;

allowing a lookup of the value for the key HOME in the dictionary environment to be written as

String home = environment["HOME"]

which obviously is syntactic, but very tasteful, sugar.

With the indexing expression being the elements of a tuple, multi dimensional arrays can be indexed using a[x, y, z], which obviously is rather different from a[x][y][y].

[Note: Multi-dimensional arrays are not provided by the standard environment, but there is nothing making them impossible.]


Go to the first, previous, next, last section, table of contents.