RULES FOR DRAWING BOX-AND-POINTER DIAGRAMS
Rules for creation of new pairs in a diagram
- cons always creates exactly one new pair.
- The number of new pairs created by list is equal to the number of arguments to list.
Pointers take a program to places in a computer's memory where information is stored. A pair is two attached boxes, each of which contains a datum. The left box is called the car and the right box the cdr.
Rules for drawing pointers
- For the purpose of this class, pointers are always drawn at whole pairs.
- Pointers are never drawn at a variable name.
- Pointers are never drawn at a car or a cdr.
- When an arrow is touching a pair, it refers to the address of the whole pair. It never refers to a car or a cdr.
- Pointers can be drawn from any of the following:
The process for drawing a box-and-pointer diagram from a given list:
- How many elements are in this list? Draw that many pairs and connect them by cdrs, with a forward slash in the last cdr, which indicates an empty list.
- For each atomic element in the list, just write the atom in the car of the appropriate pair.
- For each element that is a pair, draw the diagram for the pair. Connect that diagram from the appropriate car.