chickadee » srfi-133 » vector-unfold

vector-unfold f length initial-seed ...procedure

The fundamental vector constructor. Creates 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 kth 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. Note that the termination condition is different from the unfold procedure of SRFI 1.


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

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 vector.

(vector-unfold (lambda (i) (vector-ref vector i))
                 (vector-length vector))