Next: , Previous: , Up: Arrays   [Contents][Index]


20.4.6 Array Indexing

Arrays are indexed using the usual notation, providing an index enclosed between square brackets with [ and ]:

(poke) [1,2,3][0]
1
(poke) [1,2,3][8#B]
2

20.4.6.1 Indexing an array by number of element

Indexing by number of element is performed by providing as index an expression that evaluates to an integral value. This value is then implicitly promoted to an unsigned 64-bit integer when needed.

The valid range for the index is [0,n] where n is the number of elements stored in the array minus one. If the passed integer is out of that range, an E_out_of_bounds exception is raised:

(poke) [1,2,3][-1]
unhandled out of bounds exception
(poke) [1,2,3][3]
unhandled out of bounds exception

20.4.6.2 Indexing an array by offset of element

Poke also provides a way to refer to the element of an array by the offset where the element appears inside the array. This is done by providing as index an expression that evaluates to an offset value. This value is then implicitly promoted to an offset with magnitude unsigned 64-bit integer and bit unit when needed.

If there is not element in the indexed array that starts exactly at the given offset then an E_out_of_bounds exception is raised.