Exercise 4-3 Original
Exercise 4.3. Rewrite Eval So, the dispatch is the do in data-directed style. Compare this with the datadirected differentiation procedure of exercise 2.73. (You may use the car of a compound expression as the type of the expression, as was appropriate for the syntax implemented In the This section.) .
Analysis
Refer to exercise 2.73.
(define operation-table make-table) (define get (operation-table ' Lookup-proc)) (define put (operation-table ' Insert-proc)) (put ' op ' quote text-of-quotation) (put ' op ' set! eval-assignment) (put ' op ' define eval-definition) (put ' op ' if eval-if) (put ' op ' lambda (Lambda (x y) ( make-procedure (lambda-parameters x) (lambda-body x) y ))) (put ' op ' begin (Lambda (x y) (eval-sequence ( Begin-sequence x ))) (put ' op ' cond (Lambda (x y) ( evaln ( Cond->if x ))) (Define (evaln expr env) (Cond ((self-evaluating expr) expr) (variable expr ) (lookup-variable-value expr env)) (get ' op (car expr)) (Applyn (get ' Op (car expr) expr ( env ))) (application expr) (Applyn (evaln (operator expr) env ) (list-of-values (operands expr) env ))) (else(error "unkown expression type--EVAL" expr)) ))
"SICP Exercise" 147 Exercise 4.3