Data Structures

Data Structures

Robbert Haarman



Besides the fundamental data types (sometimes called atoms), Scheme has a few compound data structures. These are pairs, lists, and vectors.


A pair consists of two pieces of data put together. These pieces can be of any type; numbers, symbols, and even pairs. A pair is a simple data structure, but it turns out to be very versatile and powerful.


One of the most common and powerful data structures in Scheme is the list. Scheme comes with a set of procedures to elegantly and efficiently work with lists.


A vector is much like a list, with one important difference: a list consists of pairs that contain the elements, but a vector consists only of the elements themselves in conecutive memory locations. Vectors occupy less space and their elements can be accessed quicker than in lists. On the other hand, vectors are less flexible than lists.


Procedures are first-class objects in Scheme. This means that they can be treated as values and passed as arguments to other procedures, or returned from procedures. Defining procedures (other than implicitly with define) is done using lambda.

Valid XHTML 1.1! Valid CSS! Viewable with Any Browser