正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.4.32 (cb)I gg Well, the rules make it very clear. We take the procedure object associated with the binding for cb, and we apply it. This will make-counter: drop a frame, scope it by using the same environment pointer as the procedure object, which says E5 will be scoped by E4. Not Q El, not global environment, but E4 b: (lambda ( (+n1) Q :(set! n +n1})n +n1))n Slide 12 4.33 his says that using exactly the same reasoning as before, the value of n that will get mutated is the one that is seen from E5 make-counter namely the one sitting in E4. So it gets changed by 1, and then we return that value of 1 + (set! n b:(set! n +n1))n 6001 sICP (cb) Slide 12.4.34 This says the value of the overall expression is just 1 make-counter: et! n b: (set! n +n1})n +n1))n 6001 SICP Slide 12.4.35 Capturing state in local frames procedures So what was the point of this long, drawn-out, exercise? Part of it was to let you see how the rules for the environment model evolve. They specify what happens during a computation, they e+ ca e-counter specify how expressions get meanings assigned to them through a very mechanistic set of rules n:2 But the second point was to let us understand things that b: (lambda ( involve mutation, especially mutation associated with procedures. So think about what happened with our little +n1}) counter example Here is the environment model we had b: (set! n b: (set! n 600:sk6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.4.32 Well, the rules make it very clear. We take the procedure object associated with the binding for cb, and we apply it. This will drop a frame, scope it by using the same environment pointer as the procedure object, which says E5 will be scoped by E4. Not E1, not global environment, but E4. Slide 12.4.33 This says that using exactly the same reasoning as before, the value of n that will get mutated is the one that is seen from E5, namely the one sitting in E4. So it gets changed by 1, and then we return that value, of 1. Slide 12.4.34 This says the value of the overall expression is just 1. Slide 12.4.35 So what was the point of this long, drawn-out, exercise? Part of it was to let you see how the rules for the environment model evolve. They specify what happens during a computation, they specify how expressions get meanings assigned to them through a very mechanistic set of rules. But the second point was to let us understand things that involve mutation, especially mutation associated with procedures. So think about what happened with our little counter example. Here is the environment model we had
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有