summaryrefslogtreecommitdiff
path: root/sieve
diff options
context:
space:
mode:
Diffstat (limited to 'sieve')
-rw-r--r--sieve/euler.scm35
1 files changed, 35 insertions, 0 deletions
diff --git a/sieve/euler.scm b/sieve/euler.scm
new file mode 100644
index 0000000..b3ba946
--- /dev/null
+++ b/sieve/euler.scm
@@ -0,0 +1,35 @@
+
+
+
+(use-modules (srfi srfi-41))
+
+
+
+(define base (stream-from 2))
+
+
+
+(define (curry f)
+ (lambda (x)
+ (lambda (y)
+ (f x y))))
+
+
+
+(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 (sieve input)
+ (stream-cons
+ (stream-car input)
+ (sieve (sub-merge (stream-cdr input)
+ (stream-map ((curry *) (stream-car input)) input)))))
+
+
+
+(define euler (sieve base))
+
+