4.11 Vectors
Vectors in The Racket Guide introduces vectors.
A vector is a fixed-length array with constant-time access and update of the vector slots, which are numbered from 0 to one less than the number of slots in the vector.
Two vectors are equal? if they have the same length, and if the values in corresponding slots of the vectors are equal?.
A vector can be mutable or immutable. When an immutable vector is provided to a procedure like vector-set!, the exn:fail:contract exception is raised. Vectors generated by the default reader (see Reading Strings) are immutable.
A vector can be used as a single-valued sequence (see Sequences). The elements of the vector serve as elements of the sequence. See also in-vector.
A literal or printed vector starts with #(, optionally with a number between the # and (. See Reading Vectors for information on reading vectors and Printing Vectors for information on printing vectors.
procedure
(make-vector size [v]) → vector?
size : exact-nonnegative-integer? v : any/c = 0
procedure
(vector-immutable v ...) →
(and/c vector? immutable?) v : any/c
procedure
vec : vector?
procedure
(vector-ref vec pos) → any/c
vec : vector? pos : exact-nonnegative-integer?
procedure
(vector-set! vec pos v) → void?
vec : (and/c vector? (not/c immutable?)) pos : exact-nonnegative-integer? v : any/c
procedure
(vector->list vec) → list?
vec : vector?
procedure
(list->vector lst) → vector?
lst : list?
procedure
(vector->immutable-vector vec) → (and/c vector? immutable?)
vec : vector?
procedure
(vector-fill! vec v) → void?
vec : (and/c vector? (not/c immutable?)) v : any/c
procedure
(vector-copy! dest dest-start src [ src-start src-end]) → void? dest : (and/c vector? (not/c immutable?)) dest-start : exact-nonnegative-integer? src : vector? src-start : exact-nonnegative-integer? = 0 src-end : exact-nonnegative-integer? = (vector-length src)
Examples: | |||||||||||
|
procedure
(vector->values vec [start-pos end-pos]) → any
vec : vector? start-pos : exact-nonnegative-integer? = 0 end-pos : exact-nonnegative-integer? = (vector-length vec)
procedure
(build-vector n proc) → vector?
n : exact-nonnegative-integer? proc : (exact-nonnegative-integer? . -> . any/c)
Example: | ||
|
4.11.1 Additional Vector Functions
(require racket/vector) | package: base |
procedure
(vector-set*! vec pos v ... ...) → void?
vec : (and/c vector? (not/c immutable?)) pos : exact-nonnegative-integer? v : any/c
procedure
(vector-map proc vec ...+) → vector?
proc : procedure? vec : vector?
Example: | ||
|
procedure
(vector-map! proc vec ...+) → vector?
proc : procedure? vec : vector?
Examples: | |||||||
|
procedure
(vector-append vec ...) → vector?
vec : vector?
Example: | ||
|
procedure
(vector-take vec pos) → vector?
vec : vector? pos : exact-nonnegative-integer?
Example: | ||
|
procedure
(vector-take-right vec pos) → vector?
vec : vector? pos : exact-nonnegative-integer?
Example: | ||
|
procedure
(vector-drop vec pos) → vector?
vec : vector? pos : exact-nonnegative-integer?
Example: | ||
|
procedure
(vector-drop-right vec pos) → vector?
vec : vector? pos : exact-nonnegative-integer?
Example: | ||
|
procedure
(vector-split-at vec pos) →
vector? vector? vec : vector? pos : exact-nonnegative-integer?
(values (vector-take vec pos) (vector-drop vec pos))
except that it can be faster.
Example: | ||||
|
procedure
(vector-split-at-right vec pos) →
vector? vector? vec : vector? pos : exact-nonnegative-integer?
(values (vector-take-right vec pos) (vector-drop-right vec pos))
except that it can be faster.
Example: | ||||
|
procedure
(vector-copy vec [start end]) → vector?
vec : vector? start : exact-nonnegative-integer? = 0 end : exact-nonnegative-integer? = (vector-length v)
Examples: | ||||||
|
procedure
(vector-filter pred vec) → vector?
pred : procedure? vec : vector?
Example: | ||
|
procedure
(vector-filter-not pred vec) → vector?
pred : procedure? vec : vector?
Example: | ||
|
procedure
(vector-count proc vec ...+) → exact-nonnegative-integer?
proc : procedure? vec : vector?
Examples: | ||||
|
Examples: | ||||
|
Examples: | ||||
|
procedure
(vector-member v lst) → (or/c natural-number/c #f)
v : any/c lst : vector?
Examples: | ||||
|
procedure
(vector-memv v vec) → (or/c natural-number/c #f)
v : any/c vec : vector?
Examples: | ||||
|
procedure
(vector-memq v vec) → (or/c natural-number/c #f)
v : any/c vec : vector?
Examples: | ||||
|