正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12 4.24 (define ab (make-counter 0))Ige nt to apply make-counter to o, we first look up the value of make-counter with respect to the make-counter: global environment. Since it is a procedure, which is being to applied to 0 our four-step rule applies Step one: drop a frame Q n:2 b: (lambda ( (+n1) :(set! n +n1}) Slide 12 4.25 (define cb (make-counter 0))I ge Step two: convert it into an environment by scoping that frame with the same environment pointer as the procedure being applied. Note that this means in this case pointing to the global Ge make-counter: environment (set! n +n1))n 6m19c2 (define cb (make-counter 0))I gE Slide 12.4.26 Step three: bind the formal parameter of this procedure, n, to e-counter. the value passed in, 0. Note that this is a different n than the one we had before This n lives in environment e4. The n we had for ca lives in environment el. so we have different bindings for the same name in different environments et! n 1})n Slide 12,4.27 (define cb (make-counter 0)) Relative to this environment, evaluate the body of the procedure. Remember the procedure we are applying make GeA make-counter counter, so we are going to evaluate that lambda expression with respect to E4 n:2 b: (lambda ( +n1}) b: (set! n (lambda ()(set! n (+41)n)IEA6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.4.24 Since we want to apply make-counter to 0, we first look up the value of make-counter with respect to the global environment. Since it is a procedure, which is being to applied to 0 our four-step rule applies. Step one: drop a frame. Slide 12.4.25 Step two: convert it into an environment by scoping that frame with the same environment pointer as the procedure being applied. Note that this means in this case pointing to the global environment. Slide 12.4.26 Step three: bind the formal parameter of this procedure, n, to the value passed in, 0. Note that this is a different n than the one we had before. This n lives in environment E4. The n we had for ca lives in environment E1, so we have different bindings for the same name in different environments. Slide 12.4.27 Relative to this environment, evaluate the body of the procedure. Remember the procedure we are applying, make￾counter, so we are going to evaluate that lambda expression with respect to E4
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有