Skip to main content

simple-array

simple-array Type

Supertypes:

simple-array, array, t

Description:

The type of an array that is not displaced to another array, has no fill pointer , and is not expressly adjustable is a subtype of type simple-array. The concept of a simple array exists to allow the implementation to use a specialized representation and to allow the user to declare that certain values will always be simple arrays.

The types simple-vector, simple-string, and simple-bit-vector are disjoint subtypes of type simple-array, for they respectively mean (simple-array t (*)), the union of all (simple-array c (*)) for any c being a subtype of type character, and (simple-array bit (*)).

Compound Type Specifier Kind:

Specializing.

Compound Type Specifier Syntax:

(simple-array [{element-type | *} [dimension-spec]])

dimension-spec::=rank | * | ({dimension | *}*)

Compound Type Specifier Arguments:

dimension—a valid array dimension.

element-type—a type specifier .

rank—a non-negative fixnum.

Compound Type Specifier Description:

This compound type specifier is treated exactly as the corresponding compound type specifier for type array would be treated, except that the set is further constrained to include only simple arrays.

Notes:

It is implementation-dependent whether displaced arrays, vectors with fill pointers, or arrays that are actually adjustable are simple arrays.

(simple-array *) refers to all simple arrays regardless of element type, (simple-array type specifier) refers only to those simple arrays that can result from giving type-specifier as the :element-type argument to make-array.

Expanded Reference: simple-array

The simple-array Type

A simple-array is an array that is not displaced to another array, has no fill pointer, and is not expressly adjustable. Most arrays created with plain make-array (without :adjustable, :fill-pointer, or :displaced-to) are simple arrays.

;; Simple arrays -- created without special options
(typep (make-array 5) 'simple-array)
=> T

(typep (make-array '(2 3)) 'simple-array)
=> T

;; Literal vectors and strings are simple arrays
(typep #(1 2 3) 'simple-array)
=> T

(typep "hello" 'simple-array)
=> T

Non-Simple Arrays

Arrays with fill pointers, adjustability, or displacement are not guaranteed to be simple arrays.

;; Arrays with fill pointers are not simple
(typep (make-array 5 :fill-pointer 0) 'simple-array)
=> NIL

;; Explicitly adjustable arrays are not simple
(typep (make-array 5 :adjustable t) 'simple-array)
=> NIL

Why Simple Arrays Matter

Simple arrays can often be accessed more efficiently by the compiler. Type declarations using simple-array (or subtypes like simple-vector, simple-string) can enable better optimization.

;; simple-vector is a subtype of simple-array
(subtypep 'simple-vector 'simple-array)
=> T
=> T

;; simple-string is also a subtype
(subtypep 'simple-string 'simple-array)
=> T
=> T

;; simple-bit-vector as well
(subtypep 'simple-bit-vector 'simple-array)
=> T
=> T