# SICP Solutions

### Chapter 4, Metalinguistic Abstraction

#### (a)

Code is not difficult after doing so exercises. The main part to understand is what Louis pointed out in part(b)

Here goes the code:

Output:

#### (b)

If we simply substitute let with letrec it won’t work.

The main thing to see is that variables even? and odd? are bound to the frame created by let expression. Also recall that let is nothing but a lambda definition and invocation. The invocation of lambda evaluates the arguments of let in the environment where let is defined. Thus even? and odd? are not yet binded!

Now, when we invoke even?, we start evaluating the (lambda (n) (if (= n 0) true (odd? (- n 1)))). This lambda do not get evaluated inside the generated lambda(generated for let) environment but in the environment where ‘let’ is defined. But in that environment even? and odd? are not available!

Thus odd? won’t be found and it will report error. Eg: