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
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.
To what do the following expressions evaluate (assume they are evaluated in sequence)?
7
HighlitedAnswer ;Value: 7 EndOfAnswer
-
HighlitedAnswer ;Value: #[compiled-procedure ..] EndOfAnswer
(+ 2 4)
HighlitedAnswer ;Value: 6 EndOfAnswer
(* (- 5 3) (/ 9 3))
HighlitedAnswer ;Value: 6 EndOfAnswer
(7 - 4)
HighlitedAnswer ;Error: The object 7 is not applicable EndOfAnswer
To what do the following expressions evaluate (assume they are evaluated in sequence)?
Define a procedure called average that computes the average of its two numeric arguments.
HighlitedAnswer (define average (lambda (x y) (/ (+ x y) 2))) EndOfAnswer
Use the substitution model to evaluate the following expression: (average 4 (double 4))
HighlitedAnswer
([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
Consider the following two definitions below. How are they similar and how do they differ?
(define plus +)
(define add (lambda (x y) (+ x y)))
What do think should be the values of the following expressions? (Note: these are not things you have to memorize.)