Notes: Arrays


The ICI array type is used to store "ordered collections" of objects. An array is a table of references to other objects with entries in the table identified by integer key.

Objects in an array do not need to be of the same type, they are all simply objects and an array is just an ordered collection of objects, so you can have different types of things in one array.

Arrays are indexed using integer keys. The first object in the array is at key 0, the next at key 1, and so on. If you reference an element that has yet to be set or reference past the beginning or end of the array the result is NULL.

Arrays are dynamic, growing as required. If you add an object to an array at an index past the current end of the array then the array is extended and filled with NULL objects.

Arrays do not currently automatically truncate and programmers must explicity shorten arrays by copying them to a new shorter array and dropping the reference to the previous, larger version( allowing garbage collection to do its job to free up the space). The interval() function is typically used to shorten arrays and performs an efficient copy operation.

Arrays as Stacks

A number of standard functions exist that use arrays to implement a stack data structure. These functions use the array as a push-down stack with the last element of the array being the top stack element. The implementation of arrays allows these to be efficient with O(1) execution time.

Adds an object to the end of array.

Removes and returns the last element of the array. If the array is empty NULL is returned.

Returns the last element of the array. If the optional offset is given this is an offset from the end of the array, i. e, to access the last element an offset of 0 is used, the second last element, -1, and so on.