sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit edceb3f93561dab1c688e3748bc55aa357361639
parent 533743ec841f9f8f0d56f1e345e1ceac6406f56a
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat,  3 Aug 2019 14:22:30 -0400

net: Add (net ricketyspace sicp two thirty)

Diffstat:
net/ricketyspace/sicp/two/thirty.scm | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/thirty.scm b/net/ricketyspace/sicp/two/thirty.scm @@ -0,0 +1,33 @@ +;;;; License: CC0-1.0 + +(define-module (net ricketyspace sicp two thirty) + #:export (square-tree + square-tree-steroids)) + +(define (square-tree tree) + (cond ((null? tree) '()) + ((not (pair? tree)) (* tree tree)) + (else (cons (square-tree (car tree)) + (square-tree (cdr tree)))))) + +(define (square-tree-steroids tree) + (map (lambda (sub-tree) + (if (not (pair? sub-tree)) + (* sub-tree sub-tree) + (square-tree-steroids sub-tree))) + tree)) + + +;;; Guile REPL +;;; +;;; scheme@(guile-user)> ,use (net ricketyspace sicp two thirty) +;;; scheme@(guile-user)> (square-tree +;;; (list 1 +;;; (list 2 (list 3 4) 5) +;;; (list 6 7))) +;;; $6 = (1 (4 (9 16) 25) (36 49)) +;;; scheme@(guile-user)> (square-tree-steroids +;;; (list 1 +;;; (list 2 (list 3 4) 5) +;;; (list 6 7))) +;;; $7 = (1 (4 (9 16) 25) (36 49))