正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 15.7.25 And what does the evaluation of the pieces do? Twice* imPlementation of apply ( just a symbol, so eval dispatches to a lookup, which returns (eval(twice* 4)GE) (apply (eval 'twice* GE) this list structure that captures the pieces of the procedure (map (lambda (e) (eval e GE)),(4))) Clabel, argument list, body and inherited environment) (apply (list 'compound + (x*)'(plus*** **)GE) Evaluating the arguments simply returns the list (4)since numbers are self-evaluating. Thus we are ready to apply this representation of a compound procedure to a list of argument Implementation of apply (1) Slide 15.7.26 (eval ,(twice* 4) GE) And the code for app ly indicates that we should grab(using list manipulation procedures)the formal parameters of the (map (lambda (e) (eval e GE)),(4))) app1y(1itt' comPound’(x*)(p⊥us*x*x*)GE) procedure, take the list of argument values supplied, and glue them together with respect to the original environment in which (eval ,(plus* x* x*) the procedure was created, to create a new frame. That is just (extend-env-with-new-frame'(**).(4) GEl some list manipulation that we havent detailed yet Conceptually, we know what this should do: create a new table (or environment)with the formal parameters bound to the argument list, and which is scoped by the environment in which the procedure was created And then, we walk down the tree representation for the procedure object( this version of a double bubble"), grab off the body, and we will evaluate that new expression in this new environment. Note that this is all just list manipulation, we have not evaluated any of the pieces, we are simply setting up to do that Slide 15.7.27 Implementation of apply (1) So extending the environment will be some kind of abstract data type manipulation that creates a new environment, call it ( apply (eval' twice GE) El in which those variables have been bound We are now (map (lambda (e) (eval e GE)),(4))) going to evaluate this new expression with respect to that environment extend-env-with-new-frame (x*)'(4)GE) (eva1(p1us±6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 15.7.25 And what does the evaluation of the pieces do? Twice* is just a symbol, so eval dispatches to a lookup, which returns this list structure that captures the pieces of the procedure (label, argument list, body and inherited environment). Evaluating the arguments simply returns the list (4) since numbers are self-evaluating. Thus we are ready to apply this representation of a compound procedure to a list of argument values. Slide 15.7.26 And the code for apply indicates that we should grab (using list manipulation procedures) the formal parameters of the procedure, take the list of argument values supplied, and glue them together with respect to the original environment in which the procedure was created, to create a new frame. That is just some list manipulation that we haven't detailed yet. Conceptually, we know what this should do: create a new table (or environment) with the formal parameters bound to the argument list, and which is scoped by the environment in which the procedure was created. And then, we walk down the tree representation for the procedure object (this version of a "double bubble"), grab off the body, and we will evaluate that new expression in this new environment. Note that this is all just list manipulation, we have not evaluated any of the pieces, we are simply setting up to do that. Slide 15.7.27 So extending the environment will be some kind of abstract data type manipulation that creates a new environment, call it E1, in which those variables have been bound. We are now going to evaluate this new expression with respect to that environment
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有