[plt-scheme] The place of streams?

From: Chris Stephenson (cs at cs.bilgi.edu.tr)
Date: Thu Jun 21 03:37:12 EDT 2007


It is an impressive demo of the power of laziness (in evaluation).

You can do an Erastosthenes sieve where you use the stream of primes to
filter the stream of odd integers to make the stream of primes. That way
you only get to ever divide candidates by the (relatively few) prime
numbers less than the square root of the candidate. If you then "bug"
the divide operator, you can see how few divisions get done to test a
new prime candidate.

Of course it  is still computationally a lousy primality test, but if
you want a stream of ALL the primes, then the stream way is much better
than the method you first thought of.

I don't want to spoil your fun by sending you the code. If you need it,
mail me.

Chris Stephenson
Istanbul Bilgi University

Grant Rettke wrote:
> I wrote a function that iterates through a list prime numbers until a
> predicate reports true.
> My first attempt involves generating the prime list up front, which
> takes a lot of time.
> Ideally I would only generate each prime as needed.
> It sounds like a stream could be used here, and I wouldn't need to
> rewrite my function.
> Is this the case?
> Any tips?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://lists.racket-lang.org/users/archive/attachments/20070621/b55813c1/attachment.sig>

Posted on the users mailing list.