Chapter 1, Building Abstractions with Procedures

Section - Formulating Abstractions with Higher-Order Procedures

Exercise 1.43


1
2
3
4
5
6
(define (repeated f n)
    (define (repeat rs k)
       (if (= k 1) rs (repeat (compose rs f) (dec k)))
    )
    (repeat f n)
)

Output:

1
2
> ((repeated square 2) 5)
625

As mentioned in the problem we can see that i.e. number five is raised to the -th power where is the number of repetitions.