3.9 Vectors
A vector is a fixed-length array of arbitrary values. Unlike a list, a vector supports constant-time access and update of its elements.
A vector prints similar to a list—
For a vector as an expression, an optional length can be supplied. Also, a vector as an expression implicitly quotes the forms for its content, which means that identifiers and parenthesized forms in a vector constant represent symbols and lists.
Reading Vectors in The Racket Reference documents the fine points of the syntax of vectors.
Examples: | ||||||||||
|
Like strings, a vector is either mutable or immutable, and vectors written directly as expressions are immutable.
Vectors can be converted to lists and vice versa via vector->list and list->vector; such conversions are particularly useful in combination with predefined procedures on lists. When allocating extra lists seems too expensive, consider using looping forms like for/fold, which recognize vectors as well as lists.
Example: | ||||
|
Vectors in The Racket Reference provides more on vectors and vector procedures.