# Class 18: Pairs

Reading: Pairs and Pair Structures. Lab: Pairs and Pair Structures. Back to Recursion with Natural Numbers. On to Association Lists.

Held Wednesday, February 21, 2001

Summary

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

Assignments

Notes

• Reminder: You should either do homework 3 or laboratory writeup 1.
• You should, however, look over both.
• I'm pretty sure that the first exam will include some ideas from the homework and the writeup.
• Are there questions on either?
• Reminder: I will distribute exam 1 on Friday and it will be due the following Friday.
• Don't forget the cool talk on Thursday at 4:30, I can change your Web page and you can't do anything about it (known more formally as Web Raveler: An Infrastructure for Transforming Web Pages.
• There still seem to be some serious questions about how CGI works, so we'll spend a few more minutes going over the philosophy and the practice.

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.

## Dotted Pairs

• Although we've used lists as the second parts of each cons cell, you can use other values. In this case, 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.

## History

Friday, 12 January 2001

Wednesday, 21 February 2001

• Added introductory notes and assignments.
• Updated slightly.

Back to Recursion with Natural Numbers. On to Association Lists.

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

This page was generated by Siteweaver on Wed May 5 12:14:55 2004.
This page may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.18.html`.