This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see VectorsCowan in WG2's repo for R7RS-large.

Vectors­Cowan

cowan
2015-12-13 11:55:11
21history
source

Some cleanup is needed to SRFI 43.

R7RS vs. SRFI 43

The R7RS procedures vector-map and vector-for-each are incompatible with SRFI 43; they do not pass the current index, but only the values. This proposal modifies SRFI 43 to eliminate the problem:

Extensions

Here are some additional vector procedures that might be Good Things if we are going to break SRFI 43 anyway. Some are from Python, some from other sources.

Partitioning

(vector-partition pred vector)

Returns two values. The first value is a newly allocated vector of the same length as vector, reordered so that the elements which satisfy pred appear in the first n elements of the vector, and the elements which do not satisfy pred appear in the remaining elements. The second value is a vector index n which is the index of the first element not satisfying pred. The ordering of the elements is preserved in all other respects . Pred may be called any number of times and in any order.

(vector-partition! pred vector)

The same as vector-partition, except that it mutates vector and returns only n.

Appending

(vector-append-subvectors ( vector start end ) ...)

Returns a vector that contains every element of each vector from start to end in the specified order. This procedure is a generalization of vector-copy.

(vector-copy-subvectors! result ( at vector start end ) ...)

Copies every element of each vector from start to end into the vector result, starting at at. The source vectors are copied in the specified order. This procedure is a generalization of vector-copy!.

Cumulation

(vector-cumulate proc seed vector)

Returns a newly allocated vector of the same length as vector. Each element is constructed by reducing (as if by vector-reduce) successive prefixes of the elements of vector. (APL scan.)