Fixed-size indexed vectors; operations homed on the Vector class.
Literal syntax: #(1 2 3), with negative indexing via the vector’s call slot.
Vector(Vector of . args)Create a vector from the given arguments.
Returns: VECTOR — New vector containing the arguments
Examples:
(Vector of 1 2 3) => #(1 2 3)(Vector make n fill)Create a vector of length n, with every element set to fill.
Parameters:
INT — Number of elementsANY — Value to fill each slot withReturns: VECTOR — New vector of length n filled with fill
(Vector build n f)Create a vector of length n where element i is (f i). Built in place – no intermediate list.
Block form: (Vector build n (x) body …) – or (i x) for the 0-based index, then the element.
Parameters:
INT — Number of elementsANY — Index -> element function, called as (f i) for i in [0, n)Returns: VECTOR — New vector of length n, element i = (f i)
Examples:
(Vector build 3 (fn (_ i) (* i i))) => #(0 1 4)(Vector vector? x)Test whether a value is a vector.
Parameters:
ANY — Value to testReturns: BOOL — True if x is a vector
(Vector ref i v)Return the element at index i of a vector; negative i counts from the end. Errors when i is out of range.
Parameters:
INT — Zero-based index; negative counts from the endVECTOR — VectorReturns: ANY — Element at index i
(Vector set! i x v)Store x at index i of a vector (in place); negative i counts from the end. Errors when i is out of range; returns the vector for chaining.
Parameters:
INT — Zero-based index; negative counts from the endANY — Value to storeVECTOR — VectorReturns: VECTOR — v
Examples:
(Vector ref 0 (Vector set! 0 99 (Vector of 1 2))) => 99(Vector length v)Return the number of elements in a vector.
Parameters:
VECTOR — VectorReturns: INT — Number of elements
(Vector ->list v)Convert a vector to a list.
Parameters:
VECTOR — Vector to convertReturns: LIST — List of the vector’s elements
(Vector from-list lst)Convert a list to a vector.
Parameters:
LIST — List to convertReturns: VECTOR — New vector containing the list’s elements
(Vector iter v)An iterator over the vector’s elements.
Parameters:
VECTOR — Vector to iterateReturns: ITER — Iterator
(Vector for-each f v)Apply f to each element in order, for its side effects; returns nil. Named for-each, matching List/Iter/Seq.
Block form: (Vector for-each (x) body … v) – or (i x) for the 0-based index, then the element.
Parameters:
CALLABLE — Applied to each element for effectVECTOR — Vector to traverseReturns: ANY — nil
(Vector map f v)A new vector of (f element), in order. Built in place – no intermediate list.
Block form: (Vector map (x) body … v) – or (i x) for the 0-based index, then the element.
Parameters:
CALLABLE — Applied to each elementVECTOR — Vector to map overReturns: VECTOR — New vector of the same length
Examples:
(Vector map (fn (_ x) (* x 2)) (Vector of 1 2 3)) => #(2 4 6)(Vector filter pred v)A new vector of the elements satisfying pred, in order.
Block form: (Vector filter (x) body … v) – or (i x) for the 0-based index, then the element.
Parameters:
CALLABLE — Kept when it answers truthyVECTOR — Vector to filterReturns: VECTOR — New vector, possibly shorter
Examples:
(Vector filter (fn (_ x) (> x 1)) (Vector of 1 2 3)) => #(2 3)(Vector fold f acc v)Left-fold: thread acc through the elements, left to right.
Block form: (Vector fold (acc x) body … acc v) – or (acc i x) with the 0-based index ahead of the element.
Parameters:
CALLABLE — Combiner, called (f acc element)ANY — Initial accumulatorVECTOR — Vector to fold overReturns: ANY — The final accumulator
Examples:
(Vector fold + 0 (Vector of 1 2 3)) => 6