I wrote this code for project euler problem 7:<br><br>(require r5rs)<br>(require srfi/41)<br><br>(define stream-primes<br> (let ((numbers (stream-cons 2 (stream-from 3 2)))<br> (filter-stream<br> (stream-lambda<br>
(divisor strm)<br> (let ((not-div<br> (lambda (dividend)<br> (not (zero? (modulo dividend divisor))))))<br> (stream-filter not-div strm)))))<br> (stream-let <br>
loop<br> ((strm numbers)<br> (primes stream-null))<br> (define prime (stream-car strm))<br> (stream-append<br> (stream prime)<br> (loop (filter-stream prime (stream-cdr strm))<br> (stream-append primes (stream prime)))))))<br>
<br>and I ran (stream-ref stream-primes 10000)<br><br>It took unreasonably long to run. Much longer than it took my python code (which uses python's generators, to which srfi/41's lazy comprehensions are as close as I can find in scheme). I'm curious as to whether this is an artifact of lazy comprehensions in scheme being slow or just my code being wrong.<br>
<br>Thank you to anyone who takes the time to read this.<br clear="all"><br>-- <br> Alex R<br>