sicp-ex-1.41



<< Previous exercise (1.40) | sicp-solutions | Next exercise (1.42) >>


 (define (double f) 
     (lambda (x) (f (f x)))) 
 (( (double (double double) ) inc) 5) 

I've got this explanation to fully understand what is happening behind the scene

 ; explicacion: 
 double1(f) = f (f) 
 double2 double1 = double1 (double1)  
 double3 double2 = double2 (double2) = double1 (double1) (double1 (double1)) 
 double1(inc) = inc(inc) 
 double1 (double1) (double1 double1(inc)) 
 double1 (double1) (double1 (inc(inc))) 
 double1 (f (f)) (inc(inc(inc(inc)))) 
 f(f(f(f))) (inc(inc(inc(inc)))) 
 16 times inc    ; en espaƱol: 16 veces inc 
 => 16 times inc(5) = 21