6.001 Structure and Interpretation of Computer Programs
Recitation #20
Friday, November 19, 2004

Review

Practice

Change the interpreter to support the following special forms, some of which should already be familiar to you from Scheme.

1. (set!* var exp) evaluates exp and assign its value to var.  Although set! in Scheme has an undefined return value, your set!* should return var's previous value.

2. (case* expr
((val val ...) consequent)
((val val ...) consequent)
...
(else* alternate))
Case* evaluates expr and compares its value (using eqv?) against each of the listed values (which are not evaluated).  When a match is found, the corresponding consequent expression is evaluated and returned as the result of the case*.  If no matches are found, the alternate expression is evaluated and returned instead.  You can assume the else* clause is required if you want.

3. (quote* expr) returns expr without evaluating it.

4. (begin* e1 e2 ... eN) evaluates each expression in sequence, returning the value of eN as its final result.

5.  (ask* obj message args ...) evaluates obj and args but not message, and then uses ask to send the message to the object. This special form allows us to avoid quoting the message all the time --- instead of writing (ask person 'NAME), a Scheme* programmer writes (ask* person NAME).

6. (define* (name arg arg ...) body) defines a procedure name with arguments (arg arg ...) and body body.