For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.12 srfi.43 - Vector library (legacy)

Module: srfi.43

This module is effectively superseded by R7RS and SRFI-133. There are a few procedures that are not compatible with R7RS and SRFI-133, and this module remains to support legacy code that depends on them.

See Vectors, and see scheme.vector - R7RS vectors, for the “modern” versions of vector library. New code should use them.

The following procedures in SRFI-43 are built-in. See Vectors, for the description.

make-vector     vector          vector?         vector-ref
vector-set!     vector-length   vector-fill!    vector-copy
vector-copy!    vector-append   vector->list    list->vector

The following procedures in SRFI-43 are supported by SRFI-133. See scheme.vector - R7RS vectors, for the description.

vector-unfold         vector-unfold-right   vector-reverse-copy
vector-reverse-copy!  vector-concatenate    vector-empty?
vector=               vector-index          vector-index-right
vector-skip           vector-skip-right     vector-binary-search
vector-any            vector-every          vector-swap!

We explain the procedures that are not listed above.

Function: vector-fold kons knil vec1 vec2 …
Function: vector-fold-right kons knil vec1 vec2 …

[SRFI-43]{srfi.43} Like vector-fold and vector-fold-right in SRFI-133, but kons takes an extra argument, the current index, as its first argument. So kons must accept n+2 arguments, where n is the number of given vectors. It is called as (kons <index> <cumulated-value> <elt1> <elt2> ...).

Gauche has fold-with-index (see Mapping over sequences) that can be used to fold vectors with index, but the argument order of kons is slightly different: It passes the index, each element from argument vectors, then cumulated values.

(use srfi.43)
(vector-fold list '() '#(a b c) '#(d e f))
  ⇒ (2 (1 (0 () a d) b e) c f)

(use gauche.sequence)
(fold-with-index list '() '#(a b c) '#(d e f))
  ⇒ (2 c f (1 b e (0 a d ())))
Function: vector-map f vec1 vec2 …
Function: vector-map! f vec1 vec2 …
Function: vector-for-each f vec1 vec2 …
Function: vector-count f vec1 vec2 …

[SRFI-43]{srfi.43} Like vector-map and vector-for-each of R7RS, and vector-map! and vector-count in srfi-133, except f takes an extra argument, the current index, as its first argument.

Gauche provides vector-map-with-index, vector-map-with-index! and vector-for-each-with-index which are the same as SRFI-43’s vector-map, vector-map! and vector-for-each, respectively. See Vectors.

(vector-map list '#(a b c))
 ⇒ #((0 a) (1 b) (2 c))
(vector-map list '#(a b c) '#(d e f g))
 ⇒ #((0 a d) (1 b e) (2 c f))
(vector-count = '#(0 2 2 4 4))
 ⇒ 3

(Note: The vector-count example calls = with two arguments, the current index and the element, for each element of the input vector. So it counts the number of occasions when the element is equal to the index.)

The generic map and for-each in gauche.collection can be used on vectors, but the mapped procedure is called without index, and the result is returned as a list. (vector-map f vec1 vec2 …) is operationally equivalent to (map-to-with-index <vector> f vec1 vec2 …). See gauche.collection - Collection framework and gauche.sequence - Sequence framework.

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

For Development HEAD DRAFTSearch (procedure/syntax/module):