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

make-array


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

Syntax

(make-array size)
size - the size [integer] of the array to be created
returns - the new array

Description

The 'make-array' function 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.

Examples

(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 XLISP vector function to create initialized arrays.

Common Lisp: Common Lisp supports multi-dimensional arrays, XLISP only supports one-dimensional arrays. In XLISP, multi-dimenstional arrays can be created by using 'arrays within arrays'. Common Lisp supports various keyword parameters that are not supported in XLISP.

See the make-array function in the XLISP 2.0 manual.

  Back to Top


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