正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 17.5.22 Result: Infinite Data Structures! Now we see that if we create procedures that manipulate these stream objects, this new data structure, we never have to worry about how long the data structure actually is. We only get the next element in order as we ask for it. This raises an interesting If we don't really care about how long the rest of the structure is. how long a structure could we make? The answer is infinitely long! Actually, that is a slight mis-speaking, let's just say indefinitely long. We can now create data structures with I leads to some very interesting behavior in terms of how #e n arbitrary length that act as if they had infinite length, and think about processes. Let's look at an example Slide 17.5.23 Result: Infinite data structures Let's give the name ones to the structure we get by cons Some very interesting behavior streaming the integer 1 onto ones itself. That sounds a eong一8txe函m1。ne)) (stream-cdr ones))e> 1 bit weird. Note that if we ask for, say, the second element in this stream, we get out a l. why is this happening Result: Infinite Data Structures Slide 17.5.24 Well defining it this way says that the name ones refers to or Some very interesting behavior (def1 ne one8(on一te品1ne器) (txem。ax《stx points to a structure created by cons-streaming the integer 1 onto a promise to get the value of the name ones when asked for it. And that says that only when we ask for the stream-cdr of this object will we evaluate this name ones, which will simply point back to the binding we created for that name as part of the definition. As a consequence, this tructure odd th6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 17.5.22 Now we see that if we create procedures that manipulate these stream objects, this new data structure, we never have to worry about how long the data structure actually is. We only get the next element in order as we ask for it. This raises an interesting question. If we don't really care about how long the rest of the structure is, how long a structure could we make? The answer is: infinitely long! Actually, that is a slight mis-speaking, let's just say indefinitely long. We can now create data structures with arbitrary length that act as if they had infinite length, and this leads to some very interesting behavior in terms of how we think about processes. Let's look at an example. Slide 17.5.23 Let's give the name ones to the structure we get by cons￾streaming the integer 1 onto ones itself. That sounds a bit weird. Note that if we ask for, say, the second element in this stream, we get out a 1. Why is this happening? Slide 17.5.24 Well defining it this way says that the name ones refers to or points to a structure created by cons-streaming the integer 1 onto a promise to get the value of the name ones when asked for it. And that says that only when we ask for the stream-cdr of this object will we evaluate this name, ones, which will simply point back to the binding we created for that name as part of the definition. As a consequence, this structure represents a very odd thing
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有