about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm
diff options
context:
space:
mode:
Diffstat (limited to 'js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm')
-rw-r--r--js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm10
1 files changed, 10 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm b/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm
new file mode 100644
index 0000000..bff92b3
--- /dev/null
+++ b/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/sieve.scm
@@ -0,0 +1,10 @@
+(define (divisible? x y) (= (remainder x y) 0))
+
+(define (sieve stream)
+  (cons-stream
+   (stream-car stream)
+   (sieve (stream-filter
+	   (lambda (x) (not (divisible? x (stream-car stream))))
+	   (stream-cdr stream)))))
+
+(define primes (sieve (stream-cdr integers)))