Vectors

A vector is a new basic type in Scheme: like a list, but not. Vectors are good if you know exactly how many elements you need ahead of time, and are going to be accessing things by number. They're also more efficient for getting and setting elements in the middle of the sequence. But it's really hard to add or delete elements—you have to make a new vector to do it!

Vector programs are all based on mutation. If you want to do a functional vector procedure, you make a new "result" vector and mutate that. Often (but not always) a vector program will also use a helper procedure that takes a single argument, an index, which is just a number you use to say where you are in the vector.

Check out the comparison of vectors and lists, which also shows the common vector procedures.

Here's some practice with vectors:

Back to Jordy's home page | Course home page