summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-03-24 05:54:29 +0000
committerrsiddharth <s@ricketyspace.net>2018-03-24 05:54:29 +0000
commit09096bfaa15c34ba4c6010cc0765658e6327c19f (patch)
tree5a4d90860db8b9391ed29e84be04de4040afcd64 /net
parent1e85131ada02788971f7128ea3c25888d4d62b69 (diff)
net: Add (net ricketyspace sicp one fortythree)
Diffstat (limited to 'net')
-rw-r--r--net/ricketyspace/sicp/one/fortythree.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/fortythree.scm b/net/ricketyspace/sicp/one/fortythree.scm
new file mode 100644
index 0000000..f84d17b
--- /dev/null
+++ b/net/ricketyspace/sicp/one/fortythree.scm
@@ -0,0 +1,24 @@
+;;;; Under Creative Commons Attribution-ShareAlike 4.0
+;;;; International. See
+;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
+;;;;
+
+(define-module (net ricketyspace sicp one fortythree)
+ #:use-module (net ricketyspace sicp one fortytwo)
+ #:export (repeated square))
+
+(define (repeated f n)
+ (cond ((= n 1) (lambda (x) (f x)))
+ (else (sicp-compose f (repeated f (1- n))))))
+
+(define (square x) (* x x))
+
+;;; GNU Guile REPL
+;;;
+;;; scheme@(guile-user)> ,re (net ricketyspace sicp one fortythree)
+;;; scheme@(guile-user)> ((repeated square 1) 5)
+;;; $7 = 25
+;;; scheme@(guile-user)> ((repeated square 2) 5)
+;;; $8 = 625
+;;; scheme@(guile-user)> ((repeated square 3) 5)
+;;; $9 = 390625