Class 27: Pairs and Pair Structures

Back to Project: Text Generation (Questions). On to Deep Recursion.

This outline is also available in PDF.

Held: Tuesday, 10 October 2006

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

Related Pages:

Notes:

• Extra credit for attending Thursday's convo on Interpretation of Race in American Museums.
• Extra credit for attending Thursday's Tuesday Extra on Women in Computer Science at Grinnell.

Overview:

• Memory and Naming.
• Pairs and Cons cells.
• Why care?
• Lab.

Behind the Scenes: Scheme and Memory

• Many of the issues we've been considering lately (e.g., naming) have a hidden dimension: The behavior is governed, in part, by the way that Scheme represents values behind the scenes, particularly how it stores values in the computer's memory.
• You can think of Scheme as maintaining a few tables that map names to values.
• Each value must be stored somewhere in memory.
• Each value must be tagged with its type. (Memory is really only a sequence of 0's and 1's; we need a way to interpret that type.)
• Different types are stored in different ways.
• Many basic values, such as moderately-sized numbers, are stored in a fixed amount of memory.
• Other values get stored in a larger, value-specific amount of memory (along with explicit or implicit info about the size).
• I'll draw some pictures in class.

Cons Cells

• One set of interesting values in Scheme 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.
• I'll also draw some pictures of these things in class.

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.

Back to Project: Text Generation (Questions). 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 Thu Nov 30 21:43:28 2006.
The source to the document was last modified on Mon Sep 4 08:43:34 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Outlines/outline.27.html.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu