From 0f9a7c7fb9d8f1c4fda02e325771ce7b3f75c637 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 25 Oct 2015 12:36:33 +1100 Subject: Factored out common scheme code into modules --- sieve/my-streams.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sieve/my-streams.scm (limited to 'sieve/my-streams.scm') diff --git a/sieve/my-streams.scm b/sieve/my-streams.scm new file mode 100644 index 0000000..6c08762 --- /dev/null +++ b/sieve/my-streams.scm @@ -0,0 +1,26 @@ + +(library (my-streams) + (export stream-ordered-diff stream-merge) + (import (rnrs base) (srfi srfi-41)) + + + +(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 (stream-merge xstrm ystrm) + (stream-match xstrm (() ystrm) ((x . xs) + (stream-match ystrm (() xstrm) ((y . ys) + (cond ((< x y) (stream-cons x (stream-merge xs ystrm))) + ((> x y) (stream-cons y (stream-merge xstrm ys))) + (else (stream-cons x (stream-merge xs ys))))))))) + + + +) -- cgit