<p dir="ltr">Ever? Or for the purpose discussed earlier?<br>
</p>
<div class="gmail_quote">On Sep 9, 2013 7:17 AM, &quot;Matthias Felleisen&quot; &lt;<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I wonder whether you really want lazy streams. -- Matthias<br>
<br>
<br>
<br>
On Sep 9, 2013, at 10:19 AM, Lawrence Woodman wrote:<br>
<br>
&gt; On 09/09/13 07:19, Stephen Chang wrote:<br>
&gt;&gt; Konrad&#39;s exactly right. Your filtered-nums blows up because you named<br>
&gt;&gt; the stream and then traversed the entire thing. In general, if you<br>
&gt;&gt; hang onto the head of the stream while traversing then the GC can&#39;t<br>
&gt;&gt; collect anything because since you have a pointer to the head, every<br>
&gt;&gt; element of the stream is still reachable.<br>
&gt;&gt;<br>
&gt;&gt; Compare to a common traversal pattern like:<br>
&gt;&gt;<br>
&gt;&gt;     (let loop ([s &lt;some stream&gt;]) ... (loop (stream-rest s)))<br>
&gt;&gt;<br>
&gt;&gt; where the head is dropped on each loop iteration.<br>
&gt;&gt;<br>
&gt;&gt; Other comments:<br>
&gt;&gt; - (stream-length (gen-filtered-nums)) is fine because there&#39;s no<br>
&gt;&gt; pointer to the head, so the GC collects as you traverse.<br>
&gt;&gt;<br>
&gt;&gt; - in-range is fine because it&#39;s constant space and not a<br>
&gt;&gt; cons-cell-based stream. It&#39;s more like a generator.<br>
&gt;&gt;<br>
&gt;&gt; - the for/sum is actually collecting while traversing, just more<br>
&gt;&gt; slowly. I&#39;m not exactly sure why, I may look into it. On my machine,<br>
&gt;&gt; it got up to 500mb or so but it finished.<br>
&gt;<br>
&gt; Thanks, and to Konrad too.  You&#39;re mention of in-range being more<br>
&gt; like a generator, actually makes me wonder whether a generator would<br>
&gt; be a better choice for processing large data sets, from databases and<br>
&gt; csv files, sequentially.  What do you think?<br>
&gt;<br>
&gt;<br>
&gt; Lorry<br>
&gt;<br>
&gt; --<br>
&gt; vLife Systems Ltd<br>
&gt; Registered Office: The Meridian, 4 Copthall House, Station Square, Coventry, CV1 2FL<br>
&gt; Registered in England and Wales No. 06477649<br>
&gt; <a href="http://vlifesystems.com" target="_blank">http://vlifesystems.com</a><br>
&gt;<br>
&gt; ____________________<br>
&gt; Racket Users list:<br>
&gt; <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
<br>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div>