Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.



type: function (subr) 
location: built-in
source file: xlbfun.c
Common LISP compatible: similar
supported on: all machines


(make-array <size> )
        <size>          -       the size (integer) of the array to be created


MAKE-ARRAY creates an array of the specified size and returns the 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.


(setq my-array (make-array 16))         ; make the array
(aref my-array 0)                       ; return 0th (first) element
(aref my-array 15)                      ; return 15th (last) element
(aref my-array 16)                      ; error: non existant element
(dotimes (i 16)                         ; set each element to its index
         (setf (aref my-array i) i))    ;     by the setf function
(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)
my-array                                ; 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. There is also the VECTOR function to create initialized arrays. For example:

(aref #(0 1 2) 1) ; returns 1

COMMON LISP COMPATIBILITY: XLISP only supports one-dimensional arrays. Common LISP supports multi-dimension arrays. Common LISP also supports various keyword parameters that are not supported in XLISP.

Go to the first, previous, next, last section, table of contents.