University of California, Berkeley
EECS Department - Computer Science Division

CS3 Lecture 24
Pairs, Lists, and Box-and-Pointer Notation
Guest Lecturer: Anjna Mehta
(many thanks to Chris Hirsch for these excellent notes! -Dan)


Overview of today's lecture


Review

Recursion Potpourri


Representing the Real World

Overview

Data Objects

Data Types

Simple

Compound

Abstraction


Dotted Pairs (Cons Pairs)

Overview

    : (define cons-1-2 (cons 1 2)) 
    ==> cons-1-2

    : cons-1-2 
    ==> (1 . 2)  ;; How dotted pairs are printed
                 ;; when the second arg is not a list.
                 ;; Don't worry about the dot, you won't 
                 ;; be required to know this detail.

    : (car cons-1-2) 
    ==> 1

    : (cdr cons-1-2)
    ==> 2


Lists

Overview

: (define list-1-2-3 (cons 1 (cons 2 (cons 3 nil))))
==> list-1-2-3

: list-1-2-3
==> (1 2 3)


Box-and-Pointer Notation

Overview

Rules

   (define one (car list-1-2-3))



 

Where to Begin

    : (cons (cons 1 nil) (cons 2 nil))
    : (cons (cons 1 (cons 2 nil)) nil)


Summary