summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
Diffstat (limited to 'net/ricketyspace')
-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