正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Implementation of apply(2) Slide 15.7.32 So now let's finish off tracing out the evaluation of our expression. We now have a new environment, the one we just created. In it there is a local binding of the name x to the value 4, and which is scoped by the global environment name value Slide 15.7.33 Implementation of apply (2) Within that environment we are evaluating the body of that eva1·(p1ua*x*x*)E1) procedure,(plus*x* x*).Of course, the evaluator (apply (mval i plusa ee) eva1eE1)}’(x*x*} doesn,'t know that this is a body of a procedure; it has simply apply ' (primitive #[add1) (list (eval 'x* El) va1'x*E1)}) rapped previous evaluations to the stage of evaluating this(apply(primitive *(add1).(4 4) procedure with respect to this environment. We can now scheme -apply #[add] .(44)) quickly step through the evolution since it is much like earlier examples This reduces to an application. Getting the first value is simply a lookup of a binding, and the map operation will simply lookup the bindings of the other expressions. Note that the first inding will be found in Ge, while the other bindings will be found in el This reduces to the application of a primitive procedure to a set of values. This then becomes an application of a built in operation, which just reduces to the expected value Implementation of environment model Slide 15.7.34 The only thing left to be done is to actually implement the environment model that is dealing with frames and environments.Here, we get to make some design choices. Up till now we have treated it as an abstract data type but we can make it much more concrete6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.7.32 So now let's finish off tracing out the evaluation of our expression. We now have a new environment, the one we just created. In it there is a local binding of the name x* to the value 4, and which is scoped by the global environment. Slide 15.7.33 Within that environment we are evaluating the body of that procedure, (plus* x* x*). Of course, the evaluator doesn't know that this is a body of a procedure; it has simply unwrapped previous evaluations to the stage of evaluating this procedure with respect to this environment. We can now quickly step through the evolution since it is much like earlier examples. This reduces to an application. Getting the first value is simply a lookup of a binding, and the map operation will simply lookup the bindings of the other expressions. Note that the first binding will be found in GE, while the other bindings will be found in E1. This reduces to the application of a primitive procedure to a set of values. This then becomes an application of a built in operation, which just reduces to the expected value. Slide 15.7.34 The only thing left to be done is to actually implement the environment model, that is, dealing with frames and environments. Here, we get to make some design choices. Up till now we have treated it as an abstract data type, but we can make it much more concrete
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有