XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

aref


Type:   -   function (subr)
Source:   -   xlbfun.c

Syntax

(aref array element)
array - specified array
element - the element number to be retrieved
returns - the value of the array element

Description

The 'aref' function 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. See the readtable section in the XLISP 2.0 Manual.

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: XLISP only supports one-dimensional arrays. Common LISP supports multi-dimension arrays.

See the aref function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next