aref
type: function (subr) location: built-in source file: xlbfun.c Common LISP compatible: similar supported on: all machines
SYNTAX
(aref <array> <element> )
<array> - specified array
<element> - the element number to be retrieved
DESCRIPTION
AREF returns the specified element out of a previously created array. Array elements may be any valid lisp data type - including lists or arrays. Arrays made by MAKE-ARRAY and accessed by AREF are base 0. This means the first element is accessed by element number 0 and the last element is accessed by element number n-1 (where n is the array size). Array elements are initialized to NIL.
EXAMPLES
(setq my-array '#(0 1 2 3 4)) ; make the array (aref my-array 0) ; return 0th (first) element (aref my-array 4) ; return 4th (last) element (aref my-array 5) ; error: non existant element my-array ; look at array (setq new (make-array 4)) ; make another array (setf (aref new 0) (make-array 4)) ; make new[0] an array of 4 (setf (aref (aref new 0) 1) 'a) ; set new[0,1] = 'a (setf (aref new 2) '(a b c)) ; set new[2] = '(a b c) new ; look at array
READ MACRO: There is a built-in read-macro for arrays - # (the hash symbol). This allows you to create arbitrary arrays with initial values without going through a MAKE-ARRAY function.
NOTE: This function returns the value of an array element. However, there is no equivalent direct function to set the value of an array element to some value. To set an element value, you must use the SETF function. The SETF function is a generalized function that allows you to set the value of arbitrary lisp entities.
COMMON LISP COMPATIBILITY: XLISP only supports one-dimensional arrays. Common LISP supports multi-dimension arrays.