I 4. Store operators in the environment 3 (define (application? e) (pair? e)) 4 5 (define (eval exp) 6 7 ((number? exp) exp) 8 ((sym (lookup exp)) (define? exp) (eval-define exp)) 10 ((if? exp) (eval-if ((application? exp)(apply (eval (car exp) 12 (map eval (cdr exp)))) (else 14 (error unknown expression exp))) 16 ;i rename scheme's apply so we can reuse the name 17 (define scheme -applyapply) 18 19 (define (apply operator operands) (if (primitive? operator) apply (get-scheme-procedure operator) operands) (error "operator not a procedure: operator))) 24 ;i primitive: an ADT that stores scheme procedure 26 (define prim-tag ' primitive) 2g (define (make-primitive scheme-proc)(list prim-tag scheme -proc)) 28 (define (primitive? e) (tag-check e prim-tag) 9(define (get-scheme-procedure prim)(cadr prim) 03234 (define environment (make-table)) (table-put! environment ' plus* (make-primitive +) 33 (table-put! environment 'greater*(make-primitive >) (table-put! environment 'true*#t 36(eval '(define* z* 9)) (eva1'(p1us*96)) 38 (eval i(if* true* 10 15)) 41 Index to procedures that have not change procedure evaluator line lookup def eval-defi 2 281 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4. Store operators in the environment (define (application? e) (pair? e)) (define (eval exp) (cond ((number? exp) exp) ((symbol? exp) (lookup exp)) ((define? exp) (eval-define exp)) ((if? exp) (eval-if exp)) ((application? exp) (apply (eval (car exp)) (map eval (cdr exp)))) (else (error "unknown expression " exp)))) ;; rename scheme’s apply so we can reuse the name (define scheme-apply apply) (define (apply operator operands) (if (primitive? operator) (scheme-apply (get-scheme-procedure operator) operands) (error "operator not a procedure: " operator))) ;; primitive: an ADT that stores scheme procedures (define prim-tag 'primitive) (define (make-primitive scheme-proc)(list prim-tag scheme-proc)) (define (primitive? e) (tag-check e prim-tag)) (define (get-scheme-procedure prim) (cadr prim)) (define environment (make-table)) (table-put! environment 'plus* (make-primitive +)) (table-put! environment 'greater* (make-primitive >)) (table-put! environment 'true* #t) (eval '(define* z* 9)) (eval '(plus* 9 6)) (eval '(if* true* 10 15)) ; Index to procedures that have not changed: ; procedure evaluator line ; ; lookup define? 2 2 22 3 ; eval-define 2 28 ; if? 3 4 ; eval-if 3 20