Next: , Up: Language Miscellanea   [Index]


14.1 Negative Indices

Some of the aime interfaces allow indexing sequences with negative integers to indicate items or positions starting with the last. Negative indexing is part the interface exposed by libaime libraries, including the list and the byte data libraries.

See The List Library.

See The Byte Data Library.

Just like positive indices refer items or positions in sequences starting with the first and thus 0 refers the first, 1 the second, 2 the third, negative indices refer items or positions starting with the last. -1 refers the last, -2 the one before the last, -3 the one before the one before the last.

The item vs position distinction is somewhat subtle. Items refer elements in the sequences, values that are. In the ‘alpha’, ‘beta’, ‘gamma’ sequence the first item is ‘alpha’, the last is ‘gamma’. If a new item is to introduced in the first position it would appear before ‘alpha’, if in the last position after ‘gamma’.

For a N long sequence the items in the sequence may be referred via positive integers ranging from 0 to N - 1. The positions from 0 to N. The first position is 0, it is the one before the first element. The one before the last element is N - 1, the one after it is N. A position for an insert operation in the ‘alpha’, ‘beta’, ‘gamma’ sequence may specify 0, 1, 2 or 3.

For a N long sequence the items in the sequence may be referred via negative integers ranging from -1 to -N. The positions from -1 to -N - 1. The last position is -1, it is the one after the last element. The one after the first element is -N, the one before it is -N - 1. A position for an insert operation in the ‘alpha’, ‘beta’, ‘gamma’ sequence may specify -1, -2, -3 or -4.


Next: Referable Objects, Up: Language Miscellanea   [Index]