正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology the operands passed in, taking the formal parameters of the procedure object, and binding them together. This new environment should extend the previous one, in case we need things from there Thus when we have a compound application, we will grab the body of the procedure and evaluate it in a new nvironment, which has access to everything in the previous environment, plus bindings for the formal parameters of the procedure to the values passed in Note what this does. Given this version of app ly we have a wonderfully cyclic structure. Eval of an expression with respect to an environment in the general case will reduce to app l ying a procedure to a set of arguments, and that will reduce in the general case to eva luating a new expression the body of the operator) with respect to a new environment. In this way, eval and app ly will work hand-in-hand in terms of unwrapping the abstractions of the procedures down to primitive operations on primitive objects Slide 15.7.7 6.Defining ne All that is left to do is to implement the"double bubble"ideaas an abstract data type. We can do that by creating a tag for a a p swlI compound procedure and having the constructor(make compound) simply glue things together in a list, with the appropriate predicate and selectors associated with this data 今工然1 abstraction. This is not the only way to do this all we need is some method for gluing things together and getting them back Implementation of lambda* Slide 15.7.8 Looking at the code helps us understand our changes, but it is probably easier to see the changes by watching the evolution of the evaluation of an expression. Let's trace through the evaluation of a lambda* expression That is, we are evaluating a tree structure whose first element is the symbol mbda*, whose second element is a list of parameters, and whose third element is an expression constituting the body of the procedure. We are evaluating this with respect to some environment, say the global environment 4 Slide 15.7.9 Implementation of lambda* As before, please follow along in the code (for part 6) So eval takes in that tree structure representing this expression and checks it for different types of expressions (number, symbol, etc. ) Eventually eval reaches the case for handling lambda* expressions, Thus, we will dispatch on type to eval-lambda, the specific procedure designed to evaluate l ambdax's6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. the operands passed in, taking the formal parameters of the procedure object, and binding them together. This new environment should extend the previous one, in case we need things from there. Thus when we have a compound application, we will grab the body of the procedure and evaluate it in a new environment, which has access to everything in the previous environment, plus bindings for the formal parameters of the procedure to the values passed in. Note what this does. Given this version of apply we have a wonderfully cyclic structure. Eval of an expression with respect to an environment in the general case will reduce to applying a procedure to a set of arguments, and that will reduce in the general case to evaluating a new expression (the body of the operator) with respect to a new environment. In this way, eval and apply will work hand-in-hand in terms of unwrapping the abstractions of the procedures down to primitive operations on primitive objects. Slide 15.7.7 All that is left to do is to implement the "double bubble" idea as an abstract data type. We can do that by creating a tag for a compound procedure and having the constructor (make￾compound) simply glue things together in a list, with the appropriate predicate and selectors associated with this data abstraction. This is not the only way to do this; all we need is some method for gluing things together and getting them back apart. Slide 15.7.8 Looking at the code helps us understand our changes, but it is probably easier to see the changes by watching the evolution of the evaluation of an expression. Let's trace through the evaluation of a lambda* expression. That is, we are evaluating a tree structure whose first element is the symbol lambda*, whose second element is a list of parameters, and whose third element is an expression constituting the body of the procedure. We are evaluating this with respect to some environment, say the global environment. Slide 15.7.9 As before, please follow along in the code (for part 6). So eval takes in that tree structure representing this expression and checks it for different types of expressions (number, symbol, etc.). Eventually eval reaches the case for handling lambda* expressions, Thus, we will dispatch on type to eval-lambda, the specific procedure designed to evaluate lambda*'s
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有