From 0a48ed023ea65d75851ba2a4151100602695a2fd Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 22 Oct 2015 14:05:21 +1100 Subject: Cleaning up source a bit --- sieve/euler.scm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'sieve/euler.scm') 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))))) -- cgit