recitation 19: interpretation ============================================================ we're writing an interpreter for scheme-like expressions (in scheme) * interpreter: "a computer program that translates an instruction and executes it before going to the next instruction" * why are we writing it in scheme? * why are we evaluating scheme-like expressions? ============================================================ general: * eval/apply: they each call each other! isn't this an infinite loop? * draw box & pointer diagram for GE * (eval '((lambda (x) (+ x x)) 3) GE) ============================================================ let's extend the interpreter to handle the following expressions! 1. (set!* var exp) evaluates exp and assign its value to var. in our new version of scheme, let's return the var's previous value instead of being undefined. 2. (case* exp ((val) consequent) ((val) consequent) ... (else* alternate)) case* evaluates exp and compares its value (using eqv?) against each of the listed val (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. 3. (quote* exp) returns exp without evaluating it. 4. (begin* e1 e2 ... eN) evaluates each expression in order, 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), we write (ask* person NAME). 6. (define* (name arg arg ...) body) defines a procedure name with arguments (arg arg ...) and body body. ============================================================