6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.3.17 name rule, is just the double bubble pointed to by that variableo mple cont d: (inc-square 4)I Ge As in the previous case, this is a compound expression need to first evaluate the subexpressions with respect to same environment. The value of inc-square, by tnc-square b:*xx)B:+1 (square y)) Example contd: (inc-square 4)I gE Slide 12.3.18 And as we saw before, our four-step rule kicks in. Step one: csquare: create a fram P: Y b:(*xx)b:(+1 inc-square I Er=>#Icompound-proe..I 6001 SIC specified by the procedure that is being appll vironment g/Example cont d: (ing-square 4)I Slide 12.3.19 Step two: turn it into an environment, by having the encloser environment pointer of the frame point to the env 1 inc-squareg Example contd: (inc-square 4)I gE Slide 12.3.20 and that we know is specified by the second part of the double bubble of the procedure being used (square y)) ind-square I cr >#Icompound-proc ..I
6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.3.17 As in the previous case, this is a compound expression, so we need to first evaluate the subexpressions with respect to the same environment. The value of inc-square, by the name rule, is just the double bubble pointed to by that variable. Slide 12.3.18 And as we saw before, our four-step rule kicks in. Step one: create a frame. Slide 12.3.19 Step two: turn it into an environment, by having the enclosing environment pointer of the frame point to the environment specified by the procedure that is being applied... Slide 12.3.20 ... and that we know is specified by the second part of the double bubble of the procedure being used
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 12.3.21 Step three: take the formal parameter of this procedure and Example cont'd: (inc-square 4)I create a binding for it in the new frame to the value of the argument passed in tnc-square (square y)) Example contd: (inc-square 4)I gE Slide 12.3. 22 Step four: take the body of that procedure object and evaluate csquare: it with respect to this new environment, that is, ( 1 (square y)) with respect to E1 P: Y b:(*xx)b:(+1 (square y)) inc-square I Er=>#Icompound-proe..I ( 1 (square y))Ie 6001 SIC Slide 12.3.23 Again. notice how we have reduced the evaluation of one Example cont'd: (inc-square 4)I gE compound expression with respect to one environment to the Ge-ine-gquare evaluation of a simpler compound expression with respect to another environment As before, to evaluate this compound expression, we first need a the values of the subexpressions. The value of with respect top: chain from El to the global environment to get the primitive ?t b:(*xx b:(+1 El is determined by the name rule, chasing up the environmen (square y)) ine-square I G #[compound-pro ddition operation. The value of l is just a self-evaluation rule ( 1(square y))El 排【prim Example contd: (inc-square 4)I gE Slide 12.3.24 So all we have left to do is get the value of (square y) with respect to E1. This is again a compound expression,being evaluated with respect to this new environment b: (* xx) ind-square I cr >#Icompound-proc ..I quare y))I +|=>#[pxim El
6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 12.3.21 Step three: take the formal parameter of this procedure and create a binding for it in the new frame, to the value of the argument passed in. Slide 12.3.22 Step four: take the body of that procedure object and evaluate it with respect to this new environment, that is, (+ 1 (square y)) with respect to E1. Slide 12.3.23 Again, notice how we have reduced the evaluation of one compound expression with respect to one environment to the evaluation of a simpler compound expression with respect to another environment. As before, to evaluate this compound expression, we first need the values of the subexpressions. The value of + with respect to E1 is determined by the name rule, chasing up the environment chain from E1 to the global environment to get the primitive addition operation. The value of 1 is just a self-evaluation rule. Slide 12.3.24 So all we have left to do is get the value of (square y) with respect to E1. This is again a compound expression, being evaluated with respect to this new environment