# SICP Solutions

### Chapter 4, Metalinguistic Abstraction

#### Exercise 4.3

Since it was becoming difficult to verify programs because the whole evaluator is not yet built in the book, i went ahead and read till section 4.1.4.

Now, after reading that, now we can use the evaluator presented in the book whose complete code can be found here.

Note: We should not re-load the same code again while using repl. Else our evaluator code can get in conflict with the implementation language, in particular the apply procedure!

If one wants to reload, then repl should be reset/restarted. In MIT scheme, this can be done using (ge (make-top-level-environment)). I put this line at the top of the evaluator code thus need not to remember resetting, every time when I reload.

I have added a small check for exiting from the evaluator by typing exit on the evaluator prompt.

#### Solution

Note the use of apply-in-underlying-scheme while invoking exp-handler inside eval. We should not use apply here because we have changed the definition of apply.

But why we used apply in the application? part in eval? Because at that point we are here invoking the procedure defined in our defined language!

Finally consider the use of data-driven style which was the main point of the exercise. The advantage here we can see is when we add a new expression-type we need not to go to the main code i.e. a separate developer using our evaluator can add a new expression type easily without touching our evaluator.

Also, it would have been better if application? part can also become part of this data-driven style using the strategey used in previous exercise.

I tested this on the example given in section 4.1.4:

#### Complete working code

The code can be downloaded from mit. Still I am presenting the complete code here with the changes corresponding to this exercise as well as to reset the repl: