next up previous
Next: About this document

MASSACHVSETTS INSTITVTE OF TECHNOLOGY
Department of Electrical Engineering and Computer Science
6.001---Structure and Interpretation of Computer Programs
Spring Semester, 1999

Recitation -- Wednesday, April 28

1. Explicit Control Evaluator: The Important Contracts

2. Adding AND to the Explicit Control Evaluator

We can also add and to our explicit-control evaluator. We first add a clause to the evaluator dispatch

EV-AND presumes that the EXP register holds the expression to be evaluated, the ENV register holds the current environment pointer, and the CONT register holds the place to jump to.

The key is to write register machine code to implement AND starting at the label EV-AND. Fill in the missing spots. Assume we've got the primitives first-conjunct and second-conjunct.

3. Tail Recursion

Does this ev-and routine handle tail recursion? For example, consider the scheme code below. What result (if any) do we get when we evaluate (list? x) in our regular scheme? How about a scheme built on top of the above explicit-control evaluator?

To see how this is working, let's evaluate the expression (and #t (and #f #t)).

to 3in to 6.5in


How could we change the code above so that it handles tail-recursion? Hint: remove lines 19 through 23 and add two lines in their place.

    19. HighlitedAnswer (restore continue) EndOfAnswer 20. HighlitedAnswer (goto (label eval-dispatch)) EndOfAnswer

Can we get rid of the new line 19 by moving another line somewhere?

HighlitedAnswer Move line 15 after line 11 EndOfAnswer

Could we remove line 14 without changing the value returned by the code? Why or why not?

HighlitedAnswer Yes, if true? is defined as anything that is not #f EndOfAnswer

How can we get rid of line 18 by changing another line?

HighlitedAnswer Change line 10 to (restore exp) EndOfAnswer





next up previous
Next: About this document



Michael E. Leventon
Wed Apr 28 13:46:11 EDT 1999