正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12 4.28 (define cb (make-counter 0))I gE And we know what evaluating a l ambda should do. It creates a procedure object, a double bubble, the code of which make-counter: has no parameter and a body that is the same as the earlier bod we created for ca. The key point is: where does the procedure Q objects environment pointer point to? To the environment in n:2 which the l ambda is being evaluated, thus to E4. Note that b: (lambda ( (+n1) this procedure thus has a different scoping than the one created for ca. It is going to capture E4, with that version of n, which b: (set! n b:(set! n n1))n (+n 1))n is different than the one we had before (lambda ()(set! n (+15)n)Iea Slide 12 4.29 And finally, that procedure object is the value returned by (define cb (make-counter 0))I ge applying(make-counter 0), and therefore the make-counter definition creates a binding for cb up in the global environment to that new procedure object Look carefully at the structure we have here. We have ca pointing to a procedure object that inherits a frame El. We have b: (lambda + ch pointing to a similar procedure object that inherits a frame o4 4. They have different bindings for the parameter n, and that (set! n b:(set! n going to allow these things to behave differently (+n1))n (lambda ()(set! n (+n15) n)IEA (cb) Slide 12 4.30 So lets finish our understanding of this process by looking at what happens when we evaluate (cb)> within the global environmen Slide 12,4.31 Here, again, is the environment structure we have so far. We have a global environment with a binding for ca to one GeA make-counter procedure object with its own frame, and a binding for cb to another procedure object with its own frame. What happens when we apply cb? n:2 b: (lambda ( +n1}) b: (set! n b: (set! n ))n 600:sk6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.4.28 And we know what evaluating a lambda should do. It creates a procedure object, a double bubble, the code of which has no parameter and a body that is the same as the earlier body we created for ca. The key point is: where does the procedure object's environment pointer point to? To the environment in which the lambda is being evaluated, thus to E4. Note that this procedure thus has a different scoping than the one created for ca. It is going to capture E4, with that version of n, which is different than the one we had before. Slide 12.4.29 And finally, that procedure object is the value returned by applying (make-counter 0), and therefore the definition creates a binding for cb up in the global environment to that new procedure object. Look carefully at the structure we have here. We have ca pointing to a procedure object that inherits a frame E1. We have cb pointing to a similar procedure object that inherits a frame E4. They have different bindings for the parameter n, and that is going to allow these things to behave differently. Slide 12.4.30 So lets finish our understanding of this process by looking at what happens when we evaluate (cb)> within the global environment. Slide 12.4.31 Here, again, is the environment structure we have so far. We have a global environment with a binding for ca to one procedure object with its own frame, and a binding for cb to another procedure object with its own frame. What happens when we apply cb?
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有