diff options
Diffstat (limited to 'sieve/euler.scm')
-rw-r--r-- | sieve/euler.scm | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sieve/euler.scm b/sieve/euler.scm index b3ba946..ac23a94 100644 --- a/sieve/euler.scm +++ b/sieve/euler.scm @@ -16,17 +16,21 @@ -(define-stream (sub-merge x y) - (if (eq? (stream-car x) (stream-car y)) - (sub-merge (stream-cdr x) (stream-cdr y)) - (stream-cons (stream-car x) (sub-merge (stream-cdr 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 (sub-merge (stream-cdr input) - (stream-map ((curry *) (stream-car input)) input))))) + (sieve (stream-ordered-diff + (stream-cdr input) + (stream-map ((curry *) (stream-car input)) input))))) |