正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.4.36 Capturing state in local frames& procedures And notice that there is a structure associated with it. what does ca look like? It's a name, bound in the global environment counter: that points to a procedure that has as its environment pointer, a pointer into a frame, in this case el, that has some local state in Q n:2 1 The only way we can get at that value of n is through a b: (lambda ( procedure whose environment pointer, through some chain of (+n1) frames, points into that frame. In this case, that is only througl b: (set! n :(set! ca +n1})n 1+ n i)) n So this structure or pattern is a common pattern Slide 12.4.37 Capturing state in local frames& procedures And in fact when we evaluated make-counter a second time and gave the result returned by it the name cb, we created make-counter: a similar pattern, but now with its own local state. Thus, each of these names specifies a procedure that has associated with it some information that belongs only to that procedure s kind of framework, that is, procedures that capture local tate and can manipulate local state, is going to be a very useful programming tool, as we are going to see in the next few lectures }) Lessons from the make-counter example Slide 12.4.38 Environment diagrams get complicated very quickly Here is a summary of the key points to take away from this exercise not to help humans frame that was active when the lambda was evaluated this effect can be used to store local state6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.4.36 And notice that there is a structure associated with it. What does ca look like? It's a name, bound in the global environment, that points to a procedure that has as its environment pointer, a pointer into a frame, in this case E1, that has some local state in it. The only way we can get at that value of n is through a procedure whose environment pointer, through some chain of frames, points into that frame. In this case, that is only through ca. So this structure or pattern is a common pattern. Slide 12.4.37 And in fact when we evaluated make-counter a second time and gave the result returned by it the name cb, we created a similar pattern, but now with its own local state. Thus, each of these names specifies a procedure that has associated with it some information that belongs only to that procedure. This kind of framework, that is, procedures that capture local state and can manipulate local state, is going to be a very useful programming tool, as we are going to see in the next few lectures. Slide 12.4.38 Here is a summary of the key points to take away from this exercise
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有