SICP Exercise 1.34
Exercise 1.34. Suppose we define the procedure
(define (f g)
(g 2))
Then we have
(f square)
4
(f (lambda (z) (* z (+ z 1))))
6
What happens if we (perversely) ask the interpreter to evaluate the combination (f f)? Explain.
SOLUTION
The code and tests are here.
Explanation:
(f f) evaluates to (f 2) which in turn results in (2 2) where the first term
is expected to be a procedure. So the evaluator doesn't accept it and gives an
error.
(define (f g)
(g 2))
Then we have
(f square)
4
(f (lambda (z) (* z (+ z 1))))
6
What happens if we (perversely) ask the interpreter to evaluate the combination (f f)? Explain.
SOLUTION
The code and tests are here.
Explanation:
(f f) evaluates to (f 2) which in turn results in (2 2) where the first term
is expected to be a procedure. So the evaluator doesn't accept it and gives an
error.
Comments
Post a Comment