A vector is an object that contains a sequence of arbitrary klisp
objects. A vector has a length that is fixed at creation time, and as
many objects, indexed from
length-1. Compared to
lists, klisp vectors use less size and have constant access time for
Vectors may be mutable or immutable. If an attempt is made to mutate an immutable vector, an error is signaled. Two immutable vectors are “eq?” iff they are “equal?”. Two mutable vectors are “eq?” if they were created by the same constructor call. Two mutable vectors are “equal?” iff they have the same length and have “equal?” objects in each position. As is the case for lists, in order to handle possibly cyclic structures, the “equal?” algorithm considers vectors as FSMs where it position is a state change. There is only one empty vector (that is, a vector of length 0) and that vector is immutable. The vector type is encapsulated.
SOURCE NOTE: The report doesn't currently include vectors. They are taken from r7rs scheme.
The primitive type predicate for type vector.
vector?returns true iff all the objects in
objectsare of type vector.
The primitive type predicates for types immutable vector and mutable vector. These return true iff all the objects in
objectsare of type immutable vector or mutable vector respectively.
make-vectorconstructs and returns a new mutable vector of length
objis specified, then all objects in the returned vector are
obj, otherwise the content of the vector is unspecified.
vector-lengthreturns the length of
vector-refreturns the object of
kis out of bounds (i.e. less than
0or greater or equal than
(vector-length vector)) an error is signaled.
vector-set!replaces the object with index
kis out of bounds, or
vectoris immutable, an error is signaled. The result returned by
vectorcontructs and return a new mutable vector composed of the object arguments.
These applicatives convert between vectors and lists. The objects returned by these applicatives are always mutable.
vector-copyconstructs and returns a new mutable vector with the same length and objects as
These applicatives convert between vectors and bytevectors. If a vector containing objects other than exact integers between 0 and 255 inclusive are passed to
vector->bytevector, an error is signaled. The objects returned by these applicatives are always mutable.
These applicatives convert between vectors and strings. If a vector containing objects other than characters is passed to
vector->string, an error is signaled. The objects returned by these applicatives are always mutable.
vector2 should have a length greater than or equal to that of vector1.
Copies the values in vector1 to the corresponding positions in vector2. If vector2 is immutable, an error is signaled. The result returned by
k2should be valid indexes in
vector. Also it should be the case that
k1 <= k2.
vector-copy-partialconstructs and returns a new mutable vector with length
k2 - k1, with the objects from
vector, starting at index
k1(inclusive) and ending at index
k2-1should be valid indexes in
vector1. Also it should be the case that
k1 <= k2. Both
k3 + (k2-k1) - 1should be valid indexes in
vector-copy-partial!copies objects k1 (inclusive) through k2 (exclusive) from
vector2is an immutable vector, an error is signaled. The result returned by
vector-fill!replaces all the objects in
vectoris an immutable vector, an error is signaled. The result returned by