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 ;Value: 7
- ;Value: #[compiled-procedure ..]
(+ 2 4) ;Value: 6
(* (- 5 3) (/ 9 3)) ;Value: 6
(7 - 4) ;Error: The object 7 is not applicable
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.
(define average (lambda (x y) (/ (+ x y) 2)))
Use the substitution model to evaluate the following expression: (average 4 (double 4))
([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
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.)