Chapter 9. Vectors

The <vector> class corresponds to the vector type, and is essentially an array which can contain arbitrary scheme objects. The size of a vector is fixed when the vector is created.

The functions make-vector and vector are used to create vectors, and the elements are accessed using vector-ref and vector-set!.

In addition to the required scheme operations, RScheme defines many functions which allow vectors to be used where lists might otherwise be used.

Since vectors are arrays, with constant-time element access, they have different performance characteristics than lists. For example, finding the length of a vector is a constant-time operation, compared to a list for which it takes time proportional to the length of the list. On the other hand, adding an element to the front of a list is a constant time operation, wheras it is a linear-time operation for vectors.

Vectors read like lists, except with a # at the beginning. For example,

#(1 2 3)
#()

Vector operations

Table of Contents
vector-append -- Concatenates a sequence of vectors
subvector -- Creates a subvector
vector-map -- Maps a function over a vector
vector-for-each -- Applies a function to elements of a vector