# Class 28: Pairs and Pair Structures

Back to Detour: Intersection. On to Deep Recursion.

Held: Tuesday, 14 October 2003

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

Related Pages:

Notes:

• By decision of the class, we will not meet on Friday.

Overview:

• Behind the scences in Scheme: Memory.
• Pairs and Cons cells.
• Dotted pairs.
• Why care.
• 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.

## Why Care?

• Why should we care about the underlying structure used for lists?
• Because it helps explain why Scheme does some things the way it does.
• Because it helps us understand the hidden costs associated with some operations.
• Because it provides background for future discussions.

## Lab

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

## History

Thursday, 28 August 2003 [Samuel A. Rebelsky]

• Created automatically.

Back to Detour: Intersection. On to Deep Recursion.

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 Dec 9 13:59:47 2003.
The source to the document was last modified on Mon Sep 1 13:30:51 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003F/Outlines/outline.28.html.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu