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.

Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions