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 12

author

cowan

comment


    

ipnr

127.11.51.1

name

VectorsCowan

readonly

0

text

This is a preliminary list of procedures for the R7RS vector library.  It is an upward compatible extension of the vector libraries of [http://www.schemers.org/Documents/Standards/R5RS/ R5RS], [http://trac.sacrideo.us/wg/raw-attachment/wiki/WikiStart/r7rs.pdf R7RS-small], and [http://srfi.schemers.org/srfi-43/srfi-43.html SRFI 43], with additional procedures that are analogous to procedures in the [http://srfi.schemers.org/srfi-1/srfi-1.html SRFI 1] list library and the [http://srfi.schemers.org/srfi-13/srfi-13.html SRFI 13] string library.  As a single exception, the `vector-copy` procedure in R7RS-small does not provide the ''fill'' argument present in SRFI 43.

The procedures that are already in R7RS-small will not be overridden by this library, and are listed only for completeness.

Numeric vector analogues of these procedures, excluding the ones in NumericVectorsCowan, will be provided in a separate library.

== Notation ==

* R5RS means the procedure is available in R5RS and R7RS-small

* R5RS+ means the procedure is available in R5RS and with additional functionality in R7RS-small and SRFI 43.

* R7RS means the procedure is available in R7RS-small and SRFI 43.

* SRFI 43 means the procedure is available in SRFI 43.

* SRFI 43+ means either the procedure is available in SRFI 43 but additional functionality is proposed (typically ''start/end'' and possibly ''at'' arguments), or an analogous procedure is available in SRFI 43.

* SRFI 13 means an analogous procedure is available in SRFI 13.

* SRFI 1 means an analogous procedure is available in SRFI 1.

* SRFI 1/13 means an analogous procedure is available in both SRFI 1 and SRFI 13.

== Constructors ==

make-vector (R5RS), vector (R5RS)  \\
vector-unfold (SRFI 43), vector-unfold-right (SRFI 43) \\
vector-copy (R7RS), vector-copy! (R7RS) \\
vector-reverse-copy (SRFI 43+), vector-reverse-copy! (SRFI 43+) \\
vector-append (R7RS), vector-append! (SRFI 1) \\
vector-append-subvectors (see below) \\
vector-concatenate (SRFI 43), vector-concatenate! (SRFI 1) \\
vector-concatenate-reverse (SRFI 13), vector-concatenate-reverse (SRFI 13) \\
vector-tabulate (SRFI 1/13), vector-tabulate! (SRFI 1/13)

== Predicates ==

vector? (R5RS), vector-empty? (SRFI 43), vector= (SRFI 43+)

== Selectors ==

vector-ref (R5RS), vector-length (R5RS) \\
vector-take (SRFI 1/13), vector-take-right (SRFI 1/13) \\
vector-drop (SRFI 1/13), vector-drop-right (SRFI 13) \\
vector-split-at (SRFI 1)

== Iteration ==

vector-fold (SRFI 43+), vector-fold-right (SRFI 43+) \\
vector-reduce (SRFI 43+), vector-reduce-right (SRFI 43+) \\
vector-map (SRFI 43+), vector-map! (SRFI 43+) \\
vector-for-each (R7RS)

The above procedures do not pass the index value to the mapping function, for compatibility with R7RS `vector-map` and `vector-fold`.  The following versions, which are compatible with SRFI 43, pass the index value as the first argument.

vector-fold-index (SRFI 43+), vector-fold-right-index (SRFI 43+) \\
vector-reduce-index (SRFI 43+), vector-reduce-right-index (SRFI 43+) \\
vector-map-index (SRFI 43+), vector-map-index! (SRFI 43+) \\
vector-for-each-index (R7RS)

== Filtering and partitioning ==

vector-count (SRFI 43+) \\
vector-filter (SRFI 1/13), vector-remove (SRFI 1/13), vector-partition (SRFI 1) \\
vector-filter! (SRFI 1), vector-remove! (SRFI 1), vector-partition! (SRFI 1)

== Deleting ==

vector-delete (SRFI 1/13), vector-delete-duplicates (SRFI 1) \\
vector-delete! (SRFI 1/13), vector-delete-duplicates! (SRFI 1)

== Prefixes and suffixes ==

vector-prefix-length (SRFI 13), vector-suffix-length (SRFI 13) \\
vector-prefix? (SRFI 13), vector-suffix? (SRFI 13)
 
== Searching ==

vector-find (SRFI 1) \\
vector-index (SRFI 43+), vector-index-right (SRFI 43+) \\
vector-skip (SRFI 43+), vector-skip-right (SRFI 43+) \\
vector-any (SRFI 43+), vector-every (SRFI 43+) \\
vector-take-while (SRFI 1+), vector-drop-while (SRFI 1+) \\
vector-binary-search (SRFI 43+) \\
vector-span (SRFI 1), vector-span! (SRFI 1) \\
vector-break (SRFI 1), vector-break! (SRFI 1)

== Mutators ==

vector-set! (R5RS), vector-swap! (SRFI 43) \\
vector-fill! (R5RS+), vector-reverse! (SRFI 43+) \\
vector-copy! (R7RS), vector-reverse-copy! (SRFI 43+)

== Conversion ==

vector->list (R5RS+), reverse-vector->list (SRFI 43+) \\
list->vector (R5RS), reverse-list->vector (SRFI 43) \\
vector->string (R7RS), string->vector (R7RS)

== Additional procedures ==

`(vector-append-subvectors `''k fill'' ( ''at vector start end'' ) ...`)`

Returns a newly allocated vector of length ''k'' after copying the portion of each ''vector'' from ''start'' to ''end'' into the new vector starting at ''at''.  Any additional locations are initialized with ''fill''.  This procedure is a generalization of `vector-copy` and `vector-copy!`.  Implementations may optimize this procedure using an unsafe primitive that creates an uninitialized vector, in order to avoid touching each element of the result twice.  Racket code for an analogue:

{{{
(struct range
  (from to from-vector from-vector-start))

(define (make-vector-from-pieces dim default . inits)
  (define sorted-inits (sort inits range-<))
  (let ((vector (make-vector dim)))
    (let loop ((cur 0) (inits sorted-inits))
      (cond ((null? inits)
             (vector-fill vector cur dim default))
            (else
             (define init (first inits))
             (vector-fill vector cur (range-from init) default)
             (vector-block-copy vector init)
             (loop (range-to init) (rest inits)))))
    vector))

(define (range-< range1 range2)
  (< (range-from range1)
     (range-from range2)))

(define (vector-block-copy vector range)
  (define to (range-to range))
  (define from-vector (range-from-vector range))
  (let loop ((cur (range-from range))
             (i (range-from-vector-start range)))
    (when (< cur to)
      (vector-set! vector cur (vector-ref from-vector i))
      (loop (add1 cur) (add1 i)))))

(define (vector-fill vector from to value)
  (let loop ((from from))
    (when (< from to)
      (vector-set! vector from value)
      (loop (add1 from)))))
}}}

time

2014-08-29 00:36:01

version

12