正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 17.2.7 What else do we need? Notice that we have now made a Actual VS Delayed values distinction between getting the actual value of expressions, versus simply delaying the evaluation of an expression. We need values for operators, and for primitive applications only But this means we now have two different kinds of values the actual value of the expression, versus a promise to get the value when asked for it. We need to implement those two kinds of values which we do next Actual vs Delayed valt Slide 17.2.8 First, to get the actual value of an expression with respect to an (force-it (I-eval exp env))) environment, we would expect to see a use of l-evalWe can see that inside of this procedure. But notice that evaluating that expression might itself return a delayed object. If it is a nested combination of procedures, for instance, evaluating the first level may give us back something that is still a delayed promise to get a value. So we will add one more piece. We will add a procedure called force-it, which takes argument and ensures that it is fully evaluated and not delayed hus,actual-value of an expressions will evaluate any delayed expression, and ensure that the returned value is not delayed but fully evaluated Slide 17.2.9 Actual VS Delayed values As we saw we will use actual-value inside 1 eval to get the value of the procedure. We do that because force-it (l-eval exp env))) we need to know whether the procedure is primitive or compound, in order to keep unwrapping the substitution of Cons (actual-value (first-oporand o (1t-。f- arg-va1 st-operands exps unevaluated arguments into the bodies of procedures We also need to use actual-value when a primitive pplication requires an actual set of values. Thus, list-of- arg-values should take a set of expressions and an environment, and should recursively evaluate all of the expressions in that environment. Note how we just construct a list using recursive evaluation, but here using actual-value to ensure that evaluation of the expression completely unwinds any delayed objects6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 17.2.7 What else do we need? Notice that we have now made a distinction between getting the actual value of expressions, versus simply delaying the evaluation of an expression. We need values for operators, and for primitive applications only. But this means we now have two different kinds of values: the actual value of the expression, versus a promise to get the value when asked for it. We need to implement those two kinds of values, which we do next. Slide 17.2.8 First, to get the actual value of an expression with respect to an environment, we would expect to see a use of l-eval. We can see that inside of this procedure. But notice that evaluating that expression might itself return a delayed object. If it is a nested combination of procedures, for instance, evaluating the first level may give us back something that is still a delayed promise to get a value. So we will add one more piece. We will add a procedure called force-it, which takes an argument and ensures that it is fully evaluated, and not delayed. Thus, actual-value of an expressions will evaluate any delayed expression, and ensure that the returned value is not delayed, but fully evaluated. Slide 17.2.9 As we saw, we will use actual-value inside l￾eval to get the value of the procedure. We do that because we need to know whether the procedure is primitive or compound, in order to keep unwrapping the substitution of unevaluated arguments into the bodies of procedures. We also need to use actual-value when a primitive application requires an actual set of values. Thus, list-of￾arg-values should take a set of expressions and an environment, and should recursively evaluate all of the expressions in that environment. Note how we just construct a list using recursive evaluation, but here using actual-value to ensure that evaluation of the expression completely unwinds any delayed objects
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有