# SICP Solutions

### Chapter 4, Metalinguistic Abstraction

#### Exercise 4.33

Note-1: I have put the combined(and complete) code of this exercise and the next on the next exercise page.

Note-2: I developed this code on top of earlier code where we can specify each parameter as ‘lazy’, ‘lazy-memo’.

It was difficult to test this exercise without proper display method in place. So, after testing trivial cases, I started adding the print functionality which took me to next exercise.

If we need to represent the quoted list as lazy lists, then we must make the lazy cons, car and cdr available before the interpreter/evaluator begins(i.e. asks for user input). We can achieve this simply by creating definitions of car, cdr and cons in the setup-environment.

After this, we just need to write procedures that converts the quoted expressions into lazy cons. These conversion procedures turned out to be quite simple(after doing so many evaluator exercises).

Only one thing to note here is the procedure quote-it. I have quoted arguments passed to lazy-list or customized cons. To understand why:

Implementation based reason:

• Let’s ignore the lazy part and think of implementing this code with applicative order of arguments passed to customized cons.
• Now, consider that when we evaluate the code (cons '(a b)), then if we don’t quote a and b, then they are passed as a and b as arguments to cons.
• But, since we are assuming no laziness, we will evaluate a and b. But a and b need not be evaluated!
• Thus, we need to apply quote-it them.

Now, I think conceptual reason or logical reason can make it more clear:

How quote needs to work?

(I saw this after checking the mit scheme behavior of quoting expressions)

• If a list is quoted, then we converts each of the item inside the list passed to it into quoted expression.
• If a symbol is quoted, then we get a list containing two elements quote and the symbol.

Here are the changes done:

Example/Test: