Next: , Previous: , Up: srfi vector spec   [Index]


2.23.4.2 Constructors

Function: make-vector size [fill] -> vector

R5RS Create and return a vector of size size, optionally filling it with fill. The default value of fill is unspecified.

Example:

(make-vector 5 3)
=> #(3 3 3 3 3)
Function: vector x ... -> vector

R5RS Create and return a vector whose elements are x ...

Example:

(vector 0 1 2 3 4)
=> #(0 1 2 3 4)
Function: vector-unfold f length initial-seed ... -> vector

The fundamental vector constructor. Create a vector whose length is length and iterates across each index k between 0 and length, applying f at each iteration to the current index and current seeds, in that order, to receive n + 1 values: first, the element to put in the k-th slot of the new vector and n new seeds for the next iteration. It is an error for the number of seeds to vary between iterations.

Examples:

(vector-unfold (lambda (i x)
                 (values x (- x 1)))
               10 0)
=> #(0 -1 -2 -3 -4 -5 -6 -7 -8 -8)

;; construct a vector of the sequence of integers
;; in the range [0,n)
(vector-unfold values n)
=> #(0 1 2 ··· n-2 n-1)

;; copy a vector
(vector-unfold (lambda (i)
                 (vector-ref vector i))
               (vector-length vector))
Function: vector-unfold-right f length initial-seed ... -> vector

Like vector-unfold, but it uses f to generate elements from right–to–left, rather than left–to–right.

Examples:

;; Construct a vector in reverse of the integers
;; in the range [0,n).
(vector-unfold-right (lambda (i x)
                       (values x (+ x 1)))
                     n 0)
=> #(n-1 n-2 ··· 2 1 0)

;; Reverse vector.
(vector-unfold-right (lambda (i x)
                       (values (vector-ref vector x) (+ x 1)))
                     (vector-length vector)
                     0)
Function: vector-copy vec [start [end [fill]]] -> vector

Allocate a new vector whose length is end - start and fills it with elements from vec, taking elements from vec starting at index start and stopping at index end.

start defaults to 0 and end defaults to the value of (vector-length vec).

If end extends beyond the length of vec, the slots in the new vector that obviously cannot be filled by elements from vec are filled with fill, whose default value is unspecified.

Examples:

(vector-copy '#(a b c d e f g h i))
=> #(a b c d e f g h i)

(vector-copy '#(a b c d e f g h i) 6)
=> #(g h i)

(vector-copy '#(a b c d e f g h i) 3 6)
=> #(d e f)

(vector-copy '#(a b c d e f g h i) 6 12 'x)
=> #(g h i x x x)
Function: vector-reverse-copy vec [start [end]] -> vector

Like vector-copy, but it copies the elements in the reverse order from vec.

Example:

(vector-reverse-copy '#(5 4 3 2 1 0) 1 5)
=> #(1 2 3 4)
Function: vector-append vec ... -> vector

Returns a newly allocated vector that contains all elements in order from the subsequent locations in vec ...

Examples:

(vector-append '#(x) '#(y))
=> #(x y)

(vector-append '#(a) '#(b c d))
=> #(a b c d)

(vector-append '#(a #(b)) '#(#(c)))
=> #(a #(b) #(c))
Function: vector-concatenate list-of-vectors -> vector

Appends each vector in list-of-vectors. This is equivalent to:

(apply vector-append list-of-vectors)

however, it may be implemented better.

Example:

(vector-concatenate '(#(a b) #(c d)))
=> #(a b c d)

Next: , Previous: , Up: srfi vector spec   [Index]