正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 15.7.28 Implementation of apply (1) Conceptually, we have some new table structure, as shown here, with a new table for the binding of x* and a pointer to (apply (eval 'twice* GE) p (lambda (e) (eval e GE))'(4)) the enclosing environment (GE). We are now evaluating with (apply (list, compound (x*).(plus* ** x*) Ge)respect to this environment El Notice how we have reduced evaluation of one expression with (eval ,(plus* x* x*) ztend-env-with-new-frame 1(**)+(4)GE respect to some environment to evaluation of a simpler (eval (plus* x* **)El expression with respect to a new, extended environment. There is a basic cycle of the environment model, and more specifically, of our evaluator Slide 15.7.29 Implementation of apply (1) Before we carry on tracing through the evaluation of this (eval '(twice* 4) ome-other-environment simpler expression with respect to this new environment, let's (apply (eval twice stop and look at an important point. Suppose we started off the (eval e GE 4)) overall evaluation of(twice* 4), not in the global environment. but in some other environment. hat would (eva1’(pLus*x*x appen? (extend-env-with-new-frame 1(**).(4)GE) The application would have to do an evaluation of the eva1’(p1usx*x*}E1 ubexpressions, and those would also be with respect to this new environment since that is passed down as part of the evaluation Implementation of apply (1) Slide 15.7.30 So at this stage we would use that same new environment (eval '(twice* 4)GBy some-other-environment) (map (lambda (e)(eval e GE),(4)) (eval '(Plus* x***) (extend -env-with-new-frame ' (**).(4)GE)) (eval (plus* x* **) El E1 Slide 15.7.31 Implementation of apply (1) But when we get to the actual application, notice that here the (eval(twice* 4)By some-other-environment) environment doesn't change, because the global environment d here comes from the creation of the procedure When we apply (eval '* Ge (map (lambda (e)(eval e GE)'(4)) evaluated the lambda* expression that created the appy(1 ist + compound’(x*)·(p1us*x*x*)¢) procedure object, part of that creation as a link to the (eva1’(pLus*x*x* environment in which the I ambda was evaluated. And that (extend-env-with-new-frame.(x*).(4)(GE)) means that evaluating the body is going to extend this environment not the environment we called it in. Thus although we can evaluate this expression in any environment name value the environment that gets inherited by the procedure is exactly that one in which it was created6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.7.28 Conceptually, we have some new table structure, as shown here, with a new table for the binding of x* and a pointer to the enclosing environment (GE). We are now evaluating with respect to this environment E1. Notice how we have reduced evaluation of one expression with respect to some environment to evaluation of a simpler expression with respect to a new, extended environment. There is a basic cycle of the environment model, and more specifically, of our evaluator. Slide 15.7.29 Before we carry on tracing through the evaluation of this simpler expression with respect to this new environment, let's stop and look at an important point. Suppose we started off the overall evaluation of (twice* 4), not in the global environment, but in some other environment. What would happen? The application would have to do an evaluation of the subexpressions, and those would also be with respect to this new environment since that is passed down as part of the evaluation. Slide 15.7.30 So at this stage we would use that same new environment. Slide 15.7.31 But when we get to the actual application, notice that here the environment doesn't change, because the global environment used here comes from the creation of the procedure. When we evaluated the lambda* expression that created the procedure object, part of that creation as a link to the environment in which the lambda* was evaluated. And that means that evaluating the body is going to extend this environment, not the environment we called it in. Thus, although we can evaluate this expression in any environment, the environment that gets inherited by the procedure is exactly that one in which it was created
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有