vector
vector System Class
Class Precedence List:
vector, array, sequence, t
Description:
Any one-dimensional array is a vector .
The type vector is a subtype of type array; for all types x, (vector x) is the same as (array x (*)). The type (vector t), the type string, and the type bit-vector are disjoint subtypes of type vector.
Compound Type Specifier Kind:
Specializing.
Compound Type Specifier Syntax:
(vector [{element-type | *} [{size | *}]])
Compound Type Specifier Arguments:
size—a non-negative fixnum.
element-type—a type specifier .
Compound Type Specifier Description:
This denotes the set of specialized vectors whose element type and dimension match the specified values. Specifically:
If element-type is the symbol *, vectors are not excluded on the basis of their element type. Otherwise, only those vectors are included whose actual array element type is the result of upgrading element-type; see Section 15.1.2.1 (Array Upgrading).
If a size is specified, the set includes only those vectors whose only dimension is size. If the symbol * is specified instead of a size, the set is not restricted on the basis of dimension.
See Also:
Section 15.1.2.2 (Required Kinds of Specialized Arrays), Section 2.4.8.3 (Sharpsign Left Parenthesis), Section 22.1.3.7 (Printing Other Vectors), Section 2.4.8.12 (Sharpsign A)
Notes:
The type (vector e s) is equivalent to the type (array e (s)).
The type (vector bit) has the name bit-vector.
The union of all types (vector C), where C is any subtype of character, has the name string.
(vector *) refers to all vectors regardless of element type, (vector type-specifier) refers only to those vectors that can result from giving type-specifier as the :element-type argument to make-array.
Expanded Reference: vector
The vector Type
The vector type represents one-dimensional arrays. Strings, bit vectors, and general vectors are all subtypes of vector.
(typep (make-array 5) 'vector)
=> T
(typep "hello" 'vector)
=> T
(typep #*10110 'vector)
=> T
;; Multi-dimensional arrays are NOT vectors
(typep (make-array '(2 3)) 'vector)
=> NIL
Parameterized Vector Type
The vector type specifier can be parameterized by element type and size.
;; Vector of any type with any size
(typep (vector 1 2 3) '(vector * *))
=> T
;; Vector of exactly 3 elements
(typep (vector 1 2 3) '(vector * 3))
=> T
(typep (vector 1 2 3) '(vector * 4))
=> NIL
Vectors Are Both Arrays and Sequences
Vectors are the intersection of array and sequence -- they support both array operations (like aref) and sequence operations (like map, reduce, find).
(let ((v (vector 10 20 30 40 50)))
(list (aref v 2) ; array access
(elt v 2) ; sequence access
(find 30 v) ; sequence operation
(reduce #'+ v))) ; sequence operation
=> (30 30 30 150)
Type Relationships
(subtypep 'vector 'array)
=> T
=> T
(subtypep 'string 'vector)
=> T
=> T
(subtypep 'bit-vector 'vector)
=> T
=> T