User Tools


Accessor AREF

Syntax

  • aref array &rest subscriptselement
  • (setf (aref array &rest subscripts) new-element)

Arguments and Values

Description

Accesses the array element specified by the subscripts. If no subscripts are supplied and array is zero rank, aref accesses the sole element of array.

aref ignores fill pointers. It is permissible to use aref to access any array element, whether active or not.

Examples

If the variable foo names a 3-by-5 array, then the first index could be 0, 1, or 2, and then second index could be 0, 1, 2, 3, or 4. The array elements can be referred to by using the function aref; for example, (aref foo 2 1) refers to element (2, 1) of the array.

(defparameter *alpha* (make-array 4))

*ALPHA*

(aref *alpha* 3)

implementation-dependent

(setf (aref *alpha* 3) 'sirens)

SIRENS

(aref *alpha* 3)

SIRENS

(defparameter *beta* (make-array '(2 4) :element-type '(unsigned-byte 2) :initial-contents '((0 1 2 3) (3 2 1 0))))

*BETA*

(aref *beta* 1 2)

1

(defparameter *gamma* '(0 2))

*GAMMA*

(apply #'aref *beta* *gamma*)

2

(setf (apply #'aref *beta* *gamma*) 3)

3

(apply #'aref *beta *gamma*)

3

(aref *beta* 0 2)

3

Affected By

None.

Exceptional Situations

None.

See Also

Notes

None.

\issue{CONSTANT-MODIFICATION:DISALLOW} \issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM}