1.41 Exercise 1.41
The procedure definition of double is simple:
(define (double f) (lambda (x) (f (f x))))
Evaluating (((double (double double)) inc) 5) via the substitution method is cumbersome, but we can build up the solution in parts. We know that (double inc) returns a procedure that increments its argument twice. Applying double to double and applying this to inc is going to do the following:
((double double) inc) |
= ((lambda (x) (double (double x))) inc) |
= (double (double inc)) |
The total number of increments is squared, creating a procedure that increments four times. Similarly, ((double (double double)) inc) creates a procedure that increments 4^2 = 16 times. The answer to the expression is 21.
TODO: That cumbersome derivation?