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. Use immutable? to check whether a vector is 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.
Returns #t if v is a vector, #f otherwise.
See also immutable-vector? and mutable-vector?.
Returns a mutable vector with size slots, where all slots are initialized to contain v. Note that v is shared for all elements, so for mutable data, mutating an element will affect other elements.
This function takes time proportional to size.
Returns a newly allocated mutable vector with as many slots as provided vs, where the slots are initialized to contain the given vs in order.
Returns a newly allocated immutable vector with as many slots as provided vs, where the slots contain the given vs in order.
Returns the length of vec (i.e., the number of slots in the vector).
This function takes constant time.
Returns the element in slot
posof
vec. The first slot is position
0, and the last slot is one less than
(vector-length vec).
This function takes constant time.
Updates the slot pos of vec to contain v.
This function takes constant time.
Added in version 6.90.0.15 of package base.
Compare and set operation for vectors. See
box-cas!.
Added in version 6.11.0.2 of package base.
Returns a list with the same length and elements as vec.
This function takes time proportional to the size of vec.
Returns a mutable vector with the same length and elements as lst.
This function takes time proportional to the length of lst.
Returns an immutable vector with the same length and elements as vec. If vec is itself immutable, then it is returned as the result.
This function takes time proportional to the size of vec when vec is mutable.
Changes all slots of vec to contain v.
This function takes time proportional to the size of vec.
Changes the elements of
deststarting at position
dest-startto match the elements in
srcfrom
src-start(inclusive) to
src-end(exclusive). The vectors
destand
srccan be the same vector, and in that case the destination region can overlap with the source region; the destination elements after the copy match the source elements from before the copy. If any of
dest-start,
src-start, or
src-endare out of range (taking into account the sizes of the vectors and the source and destination regions), the
exn:fail:contractexception is raised.
This function takes time proportional to (- src-end src-start).
Examples:
Returns
end-pos - start-posvalues, which are the elements of
vecfrom
start-pos(inclusive) to
end-pos(exclusive). If
start-posor
end-posare greater than
(vector-length vec), or if
end-posis less than
start-pos, the
exn:fail:contractexception is raised.
This function takes time proportional to the size of vec.
Creates a vector of
nelements by applying
procto the integers from
0to
(sub1 n)in order. If
vecis the resulting vector, then
(vector-ref vec i)is the value produced by
(proc i).
Example:
4.12.1 Additional Vector Functions๐โนReturns #t if v is empty (i.e. its length is 0), #f otherwise.
Added in version 7.4.0.4 of package base.
Updates each slot pos of vec to contain each v. The update takes place from the left so later updates overwrite earlier updates.
Applies proc to the elements of the vecs from the first elements to the last. The proc argument must accept the same number of arguments as the number of supplied vecs, and all vecs must have the same number of elements. The result is a fresh vector containing each result of proc in order.
Example:
Like
vector-map, but result of
procis inserted into the first
vecat the index that the arguments to
procwere taken from. The result is the first
vec.
Examples:
Creates a fresh vector that contains all of the elements of the given vectors in order.
Example:
Returns a fresh vector whose elements are the first
poselements of
vec. If
vechas fewer than
poselements, then the
exn:fail:contractexception is raised.
Example:
Returns a fresh vector whose elements are the last
poselements of
vec. If
vechas fewer than
poselements, then the
exn:fail:contractexception is raised.
Example:
Returns a fresh vector whose elements are the elements of
vecafter the first
poselements. If
vechas fewer than
poselements, then the
exn:fail:contractexception is raised.
Example:
Returns a fresh vector whose elements are the prefix of
vec, dropping its
pos-length tail. If
vechas fewer than
poselements, then the
exn:fail:contractexception is raised.
Examples:
Returns the same result as
(values (vector-take vec pos) (vector-drop vec pos))
except that it can be faster.
Example:
Returns the same result as
(values (vector-take-right vec pos) (vector-drop-right vec pos))
except that it can be faster.
Example:
Creates a fresh vector of size
(- end start), with all of the elements of
vecfrom
start(inclusive) to
end(exclusive).
Examples:
Creates a fresh vector with the same content as vec, except that val is the element at index pos.
Examples:
Added in version 8.11.1.10 of package base.
Creates a fresh vector of length new-size where the prefix is filled with the elements of vec and the remainder with val.
Examples:
Added in version 8.12.0.10 of package base.
Returns a fresh vector with the elements of vec for which pred produces a true value. The pred procedure is applied to each element from first to last.
Example:
Like
vector-filter, but the meaning of the
predpredicate is reversed: the result is a vector of all items for which
predreturns
#f.
Example:
Returns the number of elements of the
vec ...(taken in parallel) on which
procdoes not evaluate to
#f.
Examples:
This returns the first element in the non-empty vector vec that minimizes the result of proc.
Examples:
This returns the first element in the non-empty vector vec that maximizes the result of proc.
Examples:
Locates the first element of vec that is equal to v according to is-equal?. If such an element exists, the index of that element in vec is returned. Otherwise, the result is #f.
Examples:
Changed in version 8.15.0.1 of package base: Added the is-equal? argument.
Examples:
Like
sort, but operates on vectors; a
freshvector of length
(- end start)is returned containing the elements from indices
start(inclusive) through
end(exclusive) of
vec, but in sorted order (i.e.,
vecis not modified). This sort is stable (i.e., the order of โequalโ elements is preserved).
If end is #f, it is replaced with (vector-length vec).
Examples:
Added in version 6.6.0.5 of package base.
Like
vector-sort, but
updatesindices
start(inclusive) through
end(exclusive) of
vecby sorting them according to the
less-than?procedure.
Examples:
Added in version 6.6.0.5 of package base.
Added in version 8.11.1.10 of package base.
Changed in version 8.12.0.10: Added vector*-extend.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4