next up previous
Next: About this document

MASSACHVSETTS INSTITVTE OF TECHNOLOGY
Department of Electrical Engineering and Computer Science
6.001---Structure and Interpretation of Computer Programs
Spring Semester, 1999

Recitation -- Wednesday, February 3

0. Announcements

1. Rules for Scheme

To evaluate an expression, follow these rules:

To apply a procedure to its arguments, evaluate the body of the procedure where each parameter is replaced by the corresponding value.

To evaluate a define, evaluate the body of the define, and associate that value with the name listed in the define.

2. Simple Examples

To what do the following expressions evaluate (assume they are evaluated in sequence)?

    (* (- 5 3) (/ 9 3)) HiddenAnswer ;Value: 6 EndOfAnswer

    (7 - 4) HiddenAnswer ;Error: The object 7 is not applicable EndOfAnswer

3. More Examples

To what do the following expressions evaluate (assume they are evaluated in sequence)?

4. Writing a Procedure

Define a procedure called average that computes the average of its two numeric arguments.

    HiddenAnswer (define average (lambda (x y) (/ (+ x y) 2))) EndOfAnswer

5. Substitution Model

Use the substitution model to evaluate the following expression: (average 4 (double 4))

    HiddenAnswer ([procedure] 4 (double 4)) (double 4) ([procedure] 4) (* 2 4) ([procedure] 4 8) (/ (+ 4 8) 2) ([procedure /] (+ 4 8) 2) (+ 4 8) ([procedure /] 12 2) 6 EndOfAnswer

6. Subtleties

Consider the following two definitions below. How are they similar and how do they differ?

    (define plus +)

    (define add (lambda (x y) (+ x y)))

7. More Subtleties

What do think should be the values of the following expressions? (Note: these are not things you have to memorize.)





next up previous
Next: About this document



Michael E. Leventon
Fri Mar 19 17:13:34 EST 1999