The sieve of eratosthenes is a method of finding prime numbers.
Prime numbers are numbers that have only 2 integer factors and
they are number itself and the number one. First you list all of
the numbers greater than one. Then you eliminate the first prime
(2). After that you eliminate that prime's multiples. Then you
repeat it with the next prime number etc... Below is a program
that does this process using lazy evaluation. This code was
altered slightly by r2q2, originally coded by fuse on IRC.
Another common approach to the sieve algorithm is to use lazy
streams. See SICP for an example, and SRFI:40 for a standardized
stream library. (define mark (lambda (v a s) (if (< a (vector-
length v)) (begin (vector-set! v a '#f) (mark v (+ a s) s)))))
(define primes (lambda (n) (let ((v (make-vector n))) (vector-
fill! v '#t) (let loop ((i 0) (r '())) (cond ((>= i n) r)
((vector-ref v i) (begin (mark v i (+ i 2)) (loop (+ i 1) (cons
(+ i 2) r))) (loop (+ i 1) r))))))) If you adapt Donald E.
Knuths way of doing the Sie