Functional Problem Solving (CSC 151 2013F) : Reference

Vectors


Building Vectors

(make-vector length val)
Standard Vector Procedure. Create a new vector of length length, containing only copies of val.
(vector val_0 val_1 ... val_n)
Standard Vector Procedure. Create a new vector of size n+1 of the form #(val_0 val_1 ... val_n).

Accessing Elements by Index

(vector-ref vec n)
Standard Vector Procedure. Get the nth element of vec. Note that elements are numbered starting at 0.
(vector-set! vec k val)
Standard Vector Procedure. Set the kth element of vec to val. (Note that vectors use 0-based indexing.)

Converting Vectors

(list->vector lst)
Standard Vector Procedure. Convert lst to a vector so that the ith value in the vector is the same as the ith value in the lst.
(vector->list vec)
Standard Vector Procedure. Convert vec to a list so that the ith value in the list is the same as the ith value in the vector.

Miscellaneous

(vector? val)
Standard Vector Predicate. Determine if val is a vector.
(vector-fill! vec val)
Standard Vector Procedure. Fill vec with multiple copies of val.
(vector-length vec)
Standard Vector Procedure. Determine the size of vec.

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-2013 Janet Davis, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials are copyright by John David Stone or Henry Walker and are used with permission.)

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.