# SICP Solutions

### Chapter 5, Computing with Register Machines

#### Exercise 5.48

We can build a special form for compile-and-run in the evaluator and then in its instructions simply compile the expression and store the results in val and then jump over to external-entry.

Note that external-entry already take cares for continue and setting up the env.

Changes in file ch5-syntax.scm to support special form compile-and-run:

Changes in file ch5-eceval-compiler.scm for compile and assmbling instructions:

Now add special form in evaluator ch5-eceval-compiler.scm:

I had some difficulty in setting up the things in correct order so that no compilation error should come in a fresh start.

On a fresh start, I first load the compiler, ch5-compiler.scm and then load the file load-eceval-compiler.scm.

Here’s the output:

I first tried this by installing compile-and-run as a primitive procedure. First problem is that there is a call (start eceval) that starts the evaluator. It can work fine but this means that compile-and-run call never returns! Because (start eceval) will go into a read-eval-print loop.

A simple solution could be to set flag and branch in primitive procedure to extrenal-entry when flag is set. This did not work and even did not seem to be a good design as it will introduce a branching instruction for every primitive application.