Exercise 1.41
Define a procedure d o u b l e double double that takes a procedure of one argument as argument and returns a procedure that applies the original procedure twice. For example, if i n c inc inc is a procedure that adds 1 to its argument, then
(double inc)
should be a procedure that adds 2. What value is returned by
(((double (double double)) inc) 5)
理解了可以把过程(procedure)作为返回值的概念之后,这道题就变得非常简单, d o u b l e double double过程只需要将传进来的参数过程连续执行2次就行
(define (double f)
(lambda (x) (f (f x))))
(define (inc a)
(+ a 1))
(define (halve a)
(/ a 2))
(((double (double double)) inc) 5)
(((double double) halve) 1024)
; 执行结果:
21
64