[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.12 Vectors

Builtin Class: <vector>
A vector is a simple 1-dimensional array of Scheme objects. You can access its element by index in constant time. Once created, a vector can't be resized.

Class <vector> inherits <sequence> and you can use various generic functions such as map and fold on it. See section 9.3 gauche.collection - Collection framework, and See section 9.18 gauche.sequence - Sequence framework.

If you keep only a homogeneous numeric type, you may be able to use SRFI-4 homogenous vectors (See section 10.4 srfi-4 - Homogeneous vectors).

Function: vector? obj
[R5RS] Returns #t if obj is a vector, #f otherwise.

Function: make-vector k &optional fill
[R5RS] Creates and returns a vector with length k. If optional argument fill is given, each element of the vector is initialized by it. Otherwise, the initial value of each element is undefined.

Function: vector obj ...
[R5RS] Creates a vector whose elements are obj ....

Function: vector-length vector
[R5RS] Returns the length of a vector vector.

With gauche.collection module, you can also use a method size-of.

Function: vector-ref vector k &optional fallback
[R5RS+] Returns k-th element of vector vector.

By default, vector-ref signals an error if k is negative, or greater than or equal to the length of vector. However, if an optional argument fallback is given, it is returned for such case. This is an extension of Gauche.

With gauche.sequence module, you can also use a method ref.

Function: vector-set! vector k obj
[R5RS] Sets k-th element of the vector vector to obj. It is an error if k is negative or greater than or equal to the length of vector.

With gauche.sequence module, you can also use a setter method of ref.

Function: vector->list vector &optional start end
Function: list->vector list
[R5RS+] Converts a vector to a list, or vice versa.

The optional start and end argument of vector->list limits the range of the vector to be retrieved.

 
(vector->list '#(1 2 3 4 5))     => (1 2 3 4 5)
(list->vector '(1 2 3 4 5))      => #(1 2 3 4 5)
(vector->list '#(1 2 3 4 5) 2 4) => (3 4)

With gauche.collection module, you can use (coerce-to <list> vector) and (coerce-to <vector> list) as well.

Function: vector-fill! vector fill &optional start end
[R5RS+] Sets all elements in a vector vector to fill.

Optional start and end limits the range of effect between start-th index (inclusive) to end-th index (exclusive). Start defaults to zero, and end defaults to the length of vector. These optional arguments are Gauche's extension.

Function: vector-copy vector &optional start end
Copies a vector vector. Optional start and end arguments can be used to limit the range of vector to be copied.

 
(vector-copy '#(1 2 3 4 5))     => #(1 2 3 4 5)
(vector-copy '#(1 2 3 4 5) 2 4) => #(3 4)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html