summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-08-17 09:31:19 -0400
committerrsiddharth <s@ricketyspace.net>2019-08-17 09:31:19 -0400
commitcae3cc6d7bdfa27aa18ad4ebcb0f6724ee5d5698 (patch)
treecb36e7f58f7f73e13966d4964488d17b8d8d1db6
parentf8310270c46eac78e337d178964b98f186266427 (diff)
Add (net ricketyspace sicp two thirtytwo).
-rw-r--r--net/ricketyspace/sicp/two/thirtytwo.scm16
1 files changed, 16 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/thirtytwo.scm b/net/ricketyspace/sicp/two/thirtytwo.scm
new file mode 100644
index 0000000..31d6446
--- /dev/null
+++ b/net/ricketyspace/sicp/two/thirtytwo.scm
@@ -0,0 +1,16 @@
+;;;; License: CC0-1.0
+
+(define-module (net ricketyspace sicp two thirtytwo)
+ #:export (subsets))
+
+(define (subsets s)
+ (if (null? s)
+ (list '())
+ (let ((rest (subsets (cdr s))))
+ (append rest (map (lambda (item) (cons (car s) item)) rest)))))
+
+;;; Guile REPL
+;;;
+;;; scheme@(guile-user)> ,use (net ricketyspace sicp two thirtytwo)
+;;; scheme@(guile-user)> (subsets '(1 2 3))
+;;; $6 = (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3))