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/sundaram.scm | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) (limited to 'sieve/sundaram.scm') diff --git a/sieve/sundaram.scm b/sieve/sundaram.scm index 384bc3d..8e5bf53 100644 --- a/sieve/sundaram.scm +++ b/sieve/sundaram.scm @@ -1,36 +1,16 @@ -(use-modules (srfi srfi-41)) +(add-to-load-path (dirname (current-filename))) +(import + (srfi srfi-41) + (extra-functional) + (my-streams)) -(define base (stream-from 1)) - - - -(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 (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))))))))) +(define base (stream-from 1)) @@ -41,7 +21,7 @@ (define-stream (i-stream i) (stream-map - ((curry f) i) + (part f i) (stream-from i))) @@ -58,7 +38,7 @@ (define-stream (sieve input) (stream-map - (lambda (x) (+ 1 (* 2 x))) + (compose (part + 1) (part * 2)) (stream-ordered-diff input ij-stream))) -- cgit