(r5rs.info.gz) Vectors
Info Catalog
(r5rs.info.gz) Strings
(r5rs.info.gz) Other data types
6.3.6 Vectors
-------------
Vectors are heterogenous structures whose elements are indexed by
integers. A vector typically occupies less space than a list of the
same length, and the average time required to access a randomly chosen
element is typically less for the vector than for the list.
The _length_ of a vector is the number of elements that it contains.
This number is a non-negative integer that is fixed when the vector is
created. The _valid indexes_ of a vector are the exact non-negative
integers less than the length of the vector. The first element in a
vector is indexed by zero, and the last element is indexed by one less
than the length of the vector.
Vectors are written using the notation #(OBJ ...,). For example, a
vector of length 3 containing the number zero in element 0, the list
`(2 2 2 2)' in element 1, and the string `"Anna"' in element 2 can be
written as following:
#(0 (2 2 2 2) "Anna")
Note that this is the external representation of a vector, not an
expression evaluating to a vector. Like list constants, vector
constants must be quoted:
'#(0 (2 2 2 2) "Anna")
==> #(0 (2 2 2 2) "Anna")
-- procedure: vector? obj
Returns #t if OBJ is a vector, otherwise returns #f.
-- procedure: make-vector k
-- procedure: make-vector k fill
Returns a newly allocated vector of K elements. If a second
argument is given, then each element is initialized to FILL.
Otherwise the initial contents of each element is unspecified.
-- library procedure: vector obj ...,
Returns a newly allocated vector whose elements contain the given
arguments. Analogous to `list'.
(vector 'a 'b 'c) ==> #(a b c)
-- procedure: vector-length vector
Returns the number of elements in VECTOR as an exact integer.
-- procedure: vector-ref vector k
K must be a valid index of VECTOR. `Vector-ref' returns the
contents of element K of VECTOR.
(vector-ref '#(1 1 2 3 5 8 13 21)
5)
==> 8
(vector-ref '#(1 1 2 3 5 8 13 21)
(let ((i (round (* 2 (acos -1)))))
(if (inexact? i)
(inexact->exact i)
i)))
==> 13
-- procedure: vector-set! vector k obj
K must be a valid index of VECTOR. `Vector-set!' stores OBJ in
element K of VECTOR. The value returned by `vector-set!' is
unspecified.
(let ((vec (vector 0 '(2 2 2 2) "Anna")))
(vector-set! vec 1 '("Sue" "Sue"))
vec)
==> #(0 ("Sue" "Sue") "Anna")
(vector-set! '#(0 1 2) 1 "doe")
==> _error_ ; constant vector
-- library procedure: vector->list vector
-- library procedure: list->vector list
`Vector->list' returns a newly allocated list of the objects
contained in the elements of VECTOR. `List->vector' returns a
newly created vector initialized to the elements of the list LIST.
(vector->list '#(dah dah didah))
==> (dah dah didah)
(list->vector '(dididit dah))
==> #(dididit dah)
-- library procedure: vector-fill! vector fill
Stores FILL in every element of VECTOR. The value returned by
`vector-fill!' is unspecified.
Info Catalog
(r5rs.info.gz) Strings
(r5rs.info.gz) Other data types
automatically generated byinfo2html