正在加载图片...
2. Names 3(define (define? exp)(tag-check exp 'define*)) 5 (define (eval exp) (cond ((number? exp)exp ((sum? exp) 789012345 (eval-sum exp)) ((symbol? exp)(lookup exp) ((define? exp)(eval-define exp)) (error unknown expression exp)))) 14 variation on table Adt from March 2 lecture (only difference is 15 i that table-get returns a binding, while original version 16 returned a value) make-table void -> table 18 i table-get table, symbol ->(binding I null table-put! table, symbol, anytype - undef 20 i binding-value binding -> anytype 22(define environment (make-table)) 24 (define (lookup name) (let ((bind (table-get environment name))) (if (null? binding) (error "unbound variable: name) (binding-value binding))) 8901234 (define (eval-define exp (let ((name (cadr exp)) (defined-to-be (cadd exp))) (table-put! environment name (eval defined-to-be)) undefined)) 36 (eval (define* x* (plus*4 5))) 37(eva1'(P1u8*x*2)) 89042345 Index to procedures that have not changed procedure page eval-sum 131 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 2. Names (define (define? exp) (tag-check exp 'define*)) (define (eval exp) (cond ((number? exp) exp) ((sum? exp) (eval-sum exp)) ((symbol? exp) (lookup exp)) ((define? exp) (eval-define exp)) (else (error "unknown expression " exp)))) ; variation on table ADT from March 2 lecture (only difference is ; that table-get returns a binding, while original version ; returned a value): ; make-table void -> table ; table-get table, symbol -> (binding | null) ; table-put! table, symbol, anytype -> undef ; binding-value binding -> anytype (define environment (make-table)) (define (lookup name) (let ((binding (table-get environment name))) (if (null? binding) (error "unbound variable: " name) (binding-value binding)))) (define (eval-define exp) (let ((name (cadr exp)) (defined-to-be (caddr exp))) (table-put! environment name (eval defined-to-be)) 'undefined)) (eval '(define* x* (plus* 4 5))) (eval '(plus* x* 2)) ; Index to procedures that have not changed: ; procedure page line ; sum? 1 4 ; eval-sum 1 13
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有