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.

Source for wiki VectorsCowan version 21

author

cowan

comment


    

ipnr

127.11.51.1

name

VectorsCowan

readonly

0

text

Some cleanup is needed to [http://srfi.schemers.org/srfi-43/srfi-43.html 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:

 * `vector-fold`, `vector-fold-right`, `vector-reduce`, `vector-reduce-right`, `vector-map`, `vector-map!`, `vector-for-each` are the R7RS-compatible versions that don't transmit index values to their procedure arguments.

 * `vector-fold/index`, `vector-fold-right/index`, `vector-map/index`, `vector-map!/index`, `vector-for-each/index` do transmit index values, and are compatible with SRFI 43 conceptually but not in name.

== 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.)

time

2015-12-13 11:55:11

version

21