6.001 SICP Spring 2004 3/8/2004

Tutorial 5

Topics

Symbols and Quotation

Upcoming Deadlines

• Problem set 4 due Tuesday, 3/9 at midnight

• Lecture 10 due Wednesday, 3/10 at 9am

• Lecture 11 due Friday, 3/12 at 9am

• Project 3 due Friday, 3/19 at 6pm

Symbolic Manipulation - Boolean Formula Evaluation

Some constructors, accessors, and predicates:

(define variable? symbol?)
(define (make-variable var)
  var)
(define (variable-name exp)
  exp)
(define (or? exp)
  (and (pair? exp) (eq? (car exp) 'or)))
(define (make-or exp1 exp2)
  (list 'or exp1 exp2))
(define (or-first exp)
  (cadr exp))
(define (or-second exp)
  (caddr exp))
(define (and? exp)
  (and (pair? exp) (eq? (car exp) 'and)))
(define (make-and exp1 exp2)
  (list 'and exp1 exp2))
(define (and-first exp)
  (cadr exp))

(define (and-second exp)
  (caddr exp))

Exercise 1

Write predicate, constructor, and accessor for not.

Exercise 2

Given a formula and a list of variable assignments, decide whether the formula is #t or #f. Assume that you have a procedure (variable-value bindings vname), which takes a list of assignments and a variable name and returns the value assigned to the variable.

(define (formula-value exp bindings)