正在加载图片...
Environment model code(part of eval 6) 234567 Environment list<table> (define (extend-env-with-new-frame names values env) (let ((new-frame (make-table))) (make-bindings! names values new-frame 8 c。 ns new- frame env))) 10(define (make-bindings! names values table) f。x-each (lambda (name value)(table-put! table name value) names values)) 456789022 the initial global environment (define GE (extend-env-with-new-frame (list 'plus* 'greater (list (make-primitive +)(make-primitive >) ni1)) lookup searches the list of frames for the first match (if (null? env) 26 (error "unbound variable: name) (let ((binding (table-get (car env) name))) (if (null? binding) lookup name (cdr env)) (binding 9012345678904 define changes the first frame in the envi (let ((name (cadr exp)) (defined-to-be (caddr exp))) (table-put! (car env) name (eval defined-to-be env)) undefined)) 40(eval (define* twice* (lambda*(x*)(plus* x*x*)))GE) (eval '(twice* 4)GE) 43 Index to procedures that have not changed: procedure evaluator line 45 2 47 eval-i1 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 48 ; Environment model code (part of eval 6) ; Environment = list<table> (define (extend-env-with-new-frame names values env) (let ((new-frame (make-table))) (make-bindings! names values new-frame) (cons new-frame env))) (define (make-bindings! names values table) (for-each (lambda (name value) (table-put! table name value)) names values)) ; the initial global environment (define GE (extend-env-with-new-frame (list 'plus* 'greater*) (list (make-primitive +) (make-primitive >)) nil)) ; lookup searches the list of frames for the first match (define (lookup name env) (if (null? env) (error "unbound variable: " name) (let ((binding (table-get (car env) name))) (if (null? binding) (lookup name (cdr env)) (binding-value binding))))) ; define changes the first frame in the environment (define (eval-define exp env) (let ((name (cadr exp)) (defined-to-be (caddr exp))) (table-put! (car env) name (eval defined-to-be env)) 'undefined)) (eval '(define* twice* (lambda* (x*) (plus* x* x*))) GE) (eval '(twice* 4) GE) Index to procedures that have not changed: procedure evaluator line define? 2 3 if? 3 4 application? 4 3 eval-i
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有