正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 5.3.13 Here is a trace of the substitution model running on an exampleCommon Pattern#1: cons'ing up a list of this. Notice how the if clause unwinds this into an adjoining (dfi es em m tote-dsterval from of an element onto a recursive call to the same procedure with different arguments. Since we must get the values of the to)i)from subexpressions before we can apply the adjoin operation, we expand the recursive call out again, creating another deferred djoin operation. And we keep doing this until we get down to 4)) the base case, returning the value of the empty list. Notice that this now leaves us with an expression that will create a list, a sequence terminating in the special symbol for an empty list CommonPattern#1:cons'ing up a list Slide 5.3. 14 Now we are ready to evaluate the innermost expression, which actually creates a cons pair. To demonstrate this we have drawn in the pair to show that this is the value returned by adjoin Notice how it has the correct form for a list an11”121 :2(42:5) C001 SICP Slide 5.3.15 Common Pattern #1: cons'ing up a list The next evaluation adjoins another element onto this list, with (define (enumerate-int erval from te) the cdr pointer of the newly created cons pair pointing to the value of second argument, namely the previously created list din2《e-1(+12}4)) (d主n2(a0in3 Common Pattern #1: cons'ing up a list Slide 5.3.16 (etin e enme tof e -int erval tren to) And this of course then leads to this structure. This prints out as shown, which is the printed form for a list 益 join froa Notice the order in which the pairs are created, and notice the set of deferred operations associated with the creation of this list 24)n1(adn2《e1(+12}4) 6001 SICP6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 5.3.13 Here is a trace of the substitution model running on an example of this. Notice how the if clause unwinds this into an adjoining of an element onto a recursive call to the same procedure with different arguments. Since we must get the values of the subexpressions before we can apply the adjoin operation, we expand the recursive call out again, creating another deferred adjoin operation. And we keep doing this until we get down to the base case, returning the value of the empty list. Notice that this now leaves us with an expression that will create a list, a sequence terminating in the special symbol for an empty list. Slide 5.3.14 Now we are ready to evaluate the innermost expression, which actually creates a cons pair. To demonstrate this, we have drawn in the pair to show that this is the value returned by adjoin. Notice how it has the correct form for a list. Slide 5.3.15 The next evaluation adjoins another element onto this list, with the cdr pointer of the newly created cons pair pointing to the value of second argument, namely the previously created list. Slide 5.3.16 And this of course then leads to this structure. This prints out as shown, which is the printed form for a list. Notice the order in which the pairs are created, and notice the set of deferred operations associated with the creation of this list
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有