(use-modules (srfi srfi-41)) (define base (stream-from 2)) (define (curry f) (lambda (x) (lambda (y) (f x y)))) (define-stream (stream-ordered-diff xstrm ystrm) (stream-match xstrm (() '()) ((x . xs) (stream-match ystrm (() xstrm) ((y . ys) (cond ((< x y) (stream-cons x (stream-ordered-diff xs ystrm))) ((> x y) (stream-ordered-diff xstrm ys)) (else (stream-ordered-diff xs ys)))))))) (define-stream (sieve input) (stream-cons (stream-car input) (sieve (stream-ordered-diff (stream-cdr input) (stream-map ((curry *) (stream-car input)) input))))) (define euler (sieve base))