2015/10/09

SICP 問題1.41

(define (inc n)
  (+ 1 n))

(define (double f)
  (lambda (x)
    (f (f x))))
(define D double)
(define DD (D D))

(((D (D D)) inc) 5)
(((D DD) inc) 5)
((DD (DD inc)) 5)
((DD (D (D inc))))
((D (D (D (D inc)))) 5)
((D (D (D (lambda (x) (+ 2 x))))) 5)
((D (D (lambda (x) (+ 4 x)))) 5)
((D (lambda (x) (+ 8 x))) 5)
((lambda (x) (+ 16 x)) 5)
(+ 16 5)
21


gosh> (((double (double double)) inc) 5)
21

© 2022 wat-aro