sicp

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

commit 09096bfaa15c34ba4c6010cc0765658e6327c19f
parent 1e85131ada02788971f7128ea3c25888d4d62b69
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 24 Mar 2018 05:54:29 +0000

net: Add (net ricketyspace sicp one fortythree)

Diffstat:
net/ricketyspace/sicp/one/fortythree.scm | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/one/fortythree.scm 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