参考1.41和1.42的两个方法,写出本题的简化过程
#lang racket
(define (cube x) (* x x x))
(define (square x) (* x x))
(define (inc x) (+ 1 x))
(define (compose f g)
(lambda (x)
(f (g x))))
(define (repeated f n)
(if (= n 1)
f
(compose f (repeated f (- n 1)))))
(define (double f)
(repeated f 2))
((repeated square 2) 5)
((double square) 5)
((repeated inc 2) 5)
((repeated cube 2) 5)
运行结果
625
625
7
1953125