about summary refs log blame commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm
blob: bff92b3eee97f8ea05de659cb04e08391f5a05c9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                
(define (divisible? x y) (= (remainder x y) 0))

(define (sieve stream)
  (cons-stream
   (stream-car stream)
   (sieve (stream-filter
	   (lambda (x) (not (divisible? x (stream-car stream))))
	   (stream-cdr stream)))))

(define primes (sieve (stream-cdr integers)))