正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.2.8 Define-rule First, suppose we evaluate (define z 20)in the global environment. As I said earlier, this might be an (define z 20)I c expression that you typed into the computer, and we want to see ⊙ z:10 what happens x:3 Slide 12.2.9 Note what the rule says: create a binding or replace a binding A define special form evaluated in environment E for the variable. in this case z. in the first frame of the creates or replaces a binding in the first frame of E environment, in this case, the global environment. So that old (define z 20)I c binding for z as 10 gets replaced by a new binding of z to 20 Define-rule Slide 12.2.10 A define special form evaluated in environment E On the other hand, suppose we evaluate (define creates or replaces a binding in the first frame of E 25)with respect to El. What happens in this case? (define z 20)I sx (define 2 25)IEl z:20 Slide 12.2.11 Define-rule Remember our rule: create or replace a binding for the variable in the first frame of the environment. So in this case we do this A define special form evaluated in environment E es or replaces a binding in the first frame of E frame A. the first frame of environment el. Since there is define z 20)I gr (define z 25)IEl current binding for z in this frame. we create a new one. and ; we have now set up a shadowing of z. The z bound to 25 in z:20 Frame a will shadow the binding of z to 20 in Frame B, similar to what we saw in the previous slide6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.2.8 First, suppose we evaluate (define z 20) in the global environment. As I said earlier, this might be an expression that you typed into the computer, and we want to see what happens. Slide 12.2.9 Note what the rule says: create a binding or replace a binding for the variable, in this case z, in the first frame of the environment, in this case, the global environment. So that old binding for z as 10 gets replaced by a new binding of z to 20. Slide 12.2.10 On the other hand, suppose we evaluate (define z 25) with respect to E1. What happens in this case? Slide 12.2.11 Remember our rule: create or replace a binding for the variable in the first frame of the environment. So in this case, we do this in frame A, the first frame of environment E1. Since there is no current binding for z in this frame, we create a new one, and we have now set up a shadowing of z. The z bound to 25 in Frame A will shadow the binding of z to 20 in Frame B, similar to what we saw in the previous slide
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有