a very simple interpreter
an arithmetic evaluator
- code
(define (arith-eval exp)(cond ((pair? exp) (arith-apply (cadr exp) (arith-eval (car exp)) (arith-eval (caddr exp)))) (else exp)))
(define (arith-apply op x y)(cond ((eq? op ‘*) (* x y)) ((eq? op ‘+) (+ x y)))
- sample run
(define e ‘(2 * (3 + 4)))
(arith-eval e) ==> 14
question
- what will arith-apply look like if there are lots of primitive ops?
- how could it be coded more elegantly?
-