home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0963.lha
/
SIOD
/
scm
/
prime-stream.scm
< prev
next >
Wrap
Text File
|
1993-01-02
|
703b
|
25 lines
(define (sieve stream)
(cons-stream (head stream)
(sieve (filter
(lambda (x) (not (divisible? x (head stream))))
(tail stream)))))
(define (divisible? x y) (= (remainder x y) 0))
(define (filter pred stream)
(if (pred (head stream))
(cons-stream (head stream)
(filter pred (tail stream)))
(filter pred (tail stream))))
(define (integers-starting-from n)
(cons-stream n (integers-starting-from (1+ n))))
(define integers (integers-starting-from 2))
(define primes (sieve integers))
(define (print-stream s)
(print (head s))
(print-stream (tail s)))