(rontolisp) docs
← Functions

make-array

(make-array dimensions &key initial-element initial-contents element-type fill-pointer adjustable displaced-to displaced-index-offset)

Creates and returns a new array. dimensions is an integer for a rank-1 vector, or a non-empty list of integers for an array of any rank. :initial-element sets every cell to the given value, defaulting to nil. Elements are stored row-major with O(1) access via aref, and arrays are compared by identity (eq), so two distinct arrays are never equal. make-array and aref are not first-class function values -- #'make-array is unavailable, so call it directly.

:fill-pointer (rank-1 only) gives the vector a fill pointer: an integer sets it to that position, t to the vector size. The fill pointer is the effective length -- length and printing stop at it, while aref still reaches the full storage -- and is what vector-push/vector-pop/vector-push-extend operate on. :adjustable marks the array adjustable, reported verbatim by adjustable-array-p; an adjustable array is resized in place by adjust-array. :initial-contents fills the array from a (possibly nested) sequence, row-major, on every backend and at any rank. :element-type 'double-float/'single-float (with no fill pointer/adjustability/displacement) selects the packed float representation, and :element-type 'character under the same conditions builds a string (a rank-1 character array IS a string, the make-string result shape). :element-type 'character with :fill-pointer/:adjustable builds a fill-pointered mutable string on every backend: vector-push-extend of characters grows it, replace and (setf (char ...)) write into it in place, and it prints, compares (string=/equal, equal hash keys) and passes stringp as a string. :element-type 'character with :initial-contents copies the contents (a string, a mutable string, or a character list) into a fresh simple string. :element-type '(unsigned-byte 8), '(unsigned-byte 16) or '(unsigned-byte 32) on a rank-1 array (again with no fill pointer/adjustability/displacement, and written as a literal) selects a packed unsigned-integer vector: a store masks the value to the element width (two's-complement truncation) and a read returns it widened unsigned, a non-integer store is an error, and array-element-type reports the real (unsigned-byte n) specifier. subseq and copy-seq of a packed vector stay packed at the same width. A zero-parameter deftype name is resolved before any of these checks, so an alias selects exactly what its expansion would. Any other element type is accepted but ignored (element types are not otherwise tracked; array-element-type returns t for general arrays).

:displaced-to builds a view over another array's storage instead of allocating one: element i (row-major) of the view reads and writes element i + offset of the target, where :displaced-index-offset defaults to 0, so changes are visible in both directions. The view has its own dimensions (they may differ in rank from the target's, e.g. a vector view over a matrix row), must fit inside the target, and is inspected with array-displacement. A displaced view cannot be combined with :fill-pointer, :adjustable or :initial-element, and cannot itself be adjusted.