summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-08-10 17:19:06 -0400
committerrsiddharth <s@ricketyspace.net>2019-08-10 17:19:06 -0400
commitf8310270c46eac78e337d178964b98f186266427 (patch)
tree8fd2503a91a0c6c14ff3b5eed26b1330370979a4 /net
parentedceb3f93561dab1c688e3748bc55aa357361639 (diff)
Add (net rickteyspace sicp two thirtyone).
Diffstat (limited to 'net')
-rw-r--r--net/ricketyspace/sicp/two/thirtyone.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/thirtyone.scm b/net/ricketyspace/sicp/two/thirtyone.scm
new file mode 100644
index 0000000..6420e25
--- /dev/null
+++ b/net/ricketyspace/sicp/two/thirtyone.scm
@@ -0,0 +1,22 @@
+;;;; License: CC0-1.0
+
+(define-module (net ricketyspace sicp two thirtyone)
+ #:export (tree-map
+ square-tree))
+
+(define (tree-map fun tree)
+ (cond ((null? tree) '())
+ ((not (pair? tree)) (fun tree))
+ (else (cons (tree-map fun (car tree))
+ (tree-map fun (cdr tree))))))
+
+(define (square-tree tree) (tree-map (lambda (x) (* x x)) tree))
+
+;;; Guile REPL
+;;;
+;;; scheme@(guile-user)> ,user (net ricketyspace sicp two thirtyone)
+;;; scheme@(guile-user)> (square-tree
+;;; (list 1
+;;; (list 2 (list 3 4) 5)
+;;; (list 6 7)))
+;;; $2 = (1 (4 (9 16) 25) (36 49))