next up previous
Next: 5. THE PROGRAM FEATURE Up: 4. ARITHMETIC IN LISP Previous: 4.3 Programming with Arithmetic

4.4 The Array Feature

Provision is made in LISP 1.5 for allocating blocks of storage for data. The data may consist of numbers, atomic symbols or other S-expressions.

The pseudo-function array reserves space for arrays, and turns the name of an array into a function that can be used to fill the array or locate any element of it.

Arrays may have up to three indices. Each element (uniquely specified by its coordinates) contains a pointer to an S-expression (see Section VII).

array is a function of one argument which is a list of arrays to be declared. Each item is a list containing the name of an array, its dimensions, and the word LIST. (Non-list arrays are reserved for future developments of the LISP system.)

For example, to make an array called alpha of size 7x10, and one called beta of size 3x4x5 one should execute:

array[((ALPHA (7 10) LIST) (BETA (3 4 5) LIST))]

After this has been executed, both arrays exist, and their elements are all set to NIL. Indices range from 0 to n-1.

alpha and beta are now functions that can be used to set or locate elements of these respective arrays.

To set alpha[i,j] to x, execute -

        alpha[SET;x;i,]]

To set alpha[3,4] to (A B C) execute -

        alpha[SET,(A B C);3;4]

Inside a function or program X might be bound to (A B C), I bound to 3, and J bound to 4, in which case the setting can be done by evaluating -

        (ALPHA (QUOTE SET) X I J)

To locate an element of an array, use the array name as a function with the coordinates as axes. Thus any time after executing the previous example -

        alpha[3;4] = (A B C)

Arrays use marginal indexing for maximum speed. For most efficient results, specify dimensions in increasing order. Beta[3;4;5] is better than beta[5;3;4].

Storage for arrays is located in an area of memory called binary program space.


next up previous
Next: 5. THE PROGRAM FEATURE Up: 4. ARITHMETIC IN LISP Previous: 4.3 Programming with Arithmetic