# Class 15: Pairs and Pair Structures

Back to CGI Scripting. On to Vectors.

Held: Wednesday, 12 February 2003

Summary: Today we visit some of the behind the scenes structures in Scheme, particularly the pairs that `cons` creates.

Related Pages:

Assignments:

Notes:

• My Internet connection was down last night, so I was not able to grade your latest work. I will try to grade it tonight.
• Are there questions on the CGI lab?
• Talk on summer math research opportunities today at 4:30.

Overview:

• Behind the scences in Scheme: Memory.
• Pairs and Cons cells.
• Dotted pairs.
• Lab.

## Behind the Scenes

• In Scheme, every value that you create takes up computer memory.
• Typically, the memory allocated to a value includes the type of the value and the contents of the value.
• As you might guess, different values have their contents arranged differently.
• Scheme also keeps a table (or tables) that associates names with values in memory. (Picture to be drawn in class.)
• Why is this important? Because it can help us think about some things.

## Cons Cells

• Perhaps the most interesting values are the things that `cons` creates. We often call these cons cells or pairs
• The first value of a pair is a reference to the first parameter to cons. The second value is a reference to the second parameter.
• Let's look at some examples. (Again, pictures in class.)
• (cons 3 4)
• (cons a b)
• (cons ('a null))

## Dotted Pairs

• Although we've used lists as the second parts of each cons cell, you can use other values. If the second part of a cons cell is not a list, you get what is called a dotted pair.
• The shorthand for a dotted pair is `(x . y)`.
• You'll also see the dot at the end of a long sequence of cons cells.

## Lab

• Any questions?
• Do the lab.
• Be prepared to reflect.

## History

Thursday, 15 January 2003 [Samuel A. Rebelsky]

• Created as a mostly-blank outline.

Back to CGI Scripting. On to Vectors.

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue May 6 09:20:30 2003.
The source to the document was last modified on Thu Jan 16 15:16:12 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Outlines/outline.15.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu