This is my Clojure solution to Chapter 1, Exercise 43:
(ns sicp.ch1.ex43
(:require [sicp.ch1.ex16 :as ch1-ex16]
[sicp.ch1.ex42 :as ch1-ex42]))
(defn repeated
[f n]
(loop [g identity n n]
(if (zero? n)
g
(recur (ch1-ex42/compose f g) (dec n)))))
(comment
((repeated ch1-ex16/square 2) 5) ; => 625
#__)
No comments:
Post a Comment