Go to the first, previous, next, last section, table of contents.


Sequences, Arrays, and Vectors

Recall that the sequence type is the union of three other Lisp types: lists, vectors, and strings. In other words, any list is a sequence, any vector is a sequence, and any string is a sequence. The common property that all sequences have is that each is an ordered collection of elements.

An array is a single primitive object that has a slot for each elements. All the elements are accessible in constant time, but the length of an existing array cannot be changed. Strings and vectors are the two types of arrays.

A list is a sequence of elements, but it is not a single primitive object; it is made of cons cells, one cell per element. Finding the nth element requires looking through n cons cells, so elements farther from the beginning of the list take longer to access. But it is possible to add elements to the list, or remove elements.

The following diagram shows the relationship between these types:

          ___________________________________
         |                                   |
         |          Sequence                 |
         |  ______   ______________________  |
         | |      | |                      | |
         | | List | |         Array        | |
         | |      | |  ________   _______  | |   
         | |______| | |        | |       | | |
         |          | | Vector | | String| | |
         |          | |________| |_______| | |
         |          |______________________| |
         |___________________________________|

The elements of vectors and lists may be any Lisp objects. The elements of strings are all characters.


Go to the first, previous, next, last section, table of contents.