Hi,<div><br></div><div>I created an infinite stream of primes (using this interesting article: <a href="http://matthias.benkard.de/journal/116" target="_blank" style>http://matthias.benkard.de/journal/116</a><font color="#500050" face="arial, sans-serif">)</font></div>
<div><span style="color:rgb(80,0,80);font-family:arial,sans-serif"><br></span></div><div><span style="color:rgb(80,0,80);font-family:arial,sans-serif">I tried to create a prime-pi function:</span></div><div><font color="#500050" face="arial, sans-serif"><br>
</font></div><div><font color="#500050" face="arial, sans-serif"><div> (define (prime-pi n)</div><div> (let loop-count ([candidate-stream prime-stream])</div><div> (if (> (stream-first candidate-stream) n) </div>
<div> 0</div><div> (+ (loop-count (stream-rest candidate-stream)) 1))))</div><div><br></div><div>(prime-pi 500000) grinds and runs out of memory</div><div><br></div><div>But this little cludge makes it run just fine:</div>
<div><br></div><div><div> (define (prime-pi n)</div><div> (stream-ref prime-stream (inexact->exact (* 0.1 n))) ; cludge added to get the stream to pre-create enough primes</div><div> (let loop-count ([candidate-stream prime-stream])</div>
<div> (if (> (stream-first candidate-stream) n) </div><div> 0</div><div> (+ (loop-count (stream-rest candidate-stream)) 1))))</div></div><div><br></div><div>What am I not understanding?</div><div>
<br></div><div>Thanks,</div><div>-Joe</div></font></div>