SICP exercise 1.43
2007-06-13 17:28
253 查看
书的网页提供的Complete Code中没有. 所以加上
Exercise 1.43.
If f is a numerical function and n is a positive integer, then we can form the nth repeated
application of f, which is defined to be the function whose value at x is f(f(...(f(x))...)). For example, if
f is the function x ->x + 1, then the nth repeated application of f is the function x ->x + n. If f is the
operation of squaring a number, then the nth repeated application of f is the function that raises its
n th power. Write a procedure that takes as inputs a procedure that computes f and a argument to the 2 positive integer n and returns the procedure that computes the nth repeated application of f. Your procedure should be able to be used as follows:
((repeated square 2) 5)
625
Hint: You may find it convenient to use compose from exercise 1.42
solvation:
(define (repeated fn n)
(lambda (x)
(if (= n 1)
(fn x)
(fn ((repeated fn (- n 1)) x)))))
(define (square x)
(* x x))
Exercise 1.43.
If f is a numerical function and n is a positive integer, then we can form the nth repeated
application of f, which is defined to be the function whose value at x is f(f(...(f(x))...)). For example, if
f is the function x ->x + 1, then the nth repeated application of f is the function x ->x + n. If f is the
operation of squaring a number, then the nth repeated application of f is the function that raises its
n th power. Write a procedure that takes as inputs a procedure that computes f and a argument to the 2 positive integer n and returns the procedure that computes the nth repeated application of f. Your procedure should be able to be used as follows:
((repeated square 2) 5)
625
Hint: You may find it convenient to use compose from exercise 1.42
solvation:
(define (repeated fn n)
(lambda (x)
(if (= n 1)
(fn x)
(fn ((repeated fn (- n 1)) x)))))
(define (square x)
(* x x))
相关文章推荐
- SICP-Exercise 1.6
- 【SICP练习】38 练习1.43
- SICP 1.43
- SICP Exercise 3.52
- SICP-Exercise 1.9
- SICP Exercise 3.53
- SICP Exercise 4.7
- SICP 1.40 1.41 1.42 1.43 1.44
- SICP-Exercise 1.5
- SICP Exercise 3.54
- SICP Exercise 4.9
- SICP Exercise 1.13
- SICP Exercise 3.34
- SICP Exercise 3.55
- 【SICP练习】38 练习1.43
- SICP 练习1.43 repeated
- SICP Exercise 3.35
- SICP Exercise 4.1
- SICP Exercise 4.13
- SICP Exercise 3.11