(define (inc x) (+ x 1))

(define (double f)
  (lambda (x) (f (f x))))

;; 맞바꿈 계산법으로 확인하기
(((double (double double)) inc) 5)

(((double (lambda (x) (double (double x)))) inc) 5)

(((lambda (y) ((lambda (x) (double (double x))) ((lambda (z) (double (double z))) y))) inc) 5)

(((lambda (x) (double (double x))) ((lambda (z) (double (double z))) inc)) 5)

(((lambda (x) (double (double x))) (double (double inc))) 5)

((double (double (double (double inc)))) 5)

((double (double (double (lambda (x) (inc (inc x)))))) 5)

((double (double (lambda (a)
                   ((lambda (x) (inc (inc x)))
                    ((lambda (x) (inc (inc x))) a))))) 5)

((double (lambda (b)
           ((lambda (a)
              ((lambda (x) (inc (inc x)))
               ((lambda (x) (inc (inc x))) a)))
            ((lambda (a)
               ((lambda (x) (inc (inc x)))
                ((lambda (x) (inc (inc x))) a))) b)))) 5)
((lambda (c)
   ((lambda (b)
      ((lambda (a)
         ((lambda (x) (inc (inc x)))
          ((lambda (x) (inc (inc x))) a)))
       ((lambda (a)
          ((lambda (x) (inc (inc x)))
           ((lambda (x) (inc (inc x))) a))) b)))
    ((lambda (b)
      ((lambda (a)
         ((lambda (x) (inc (inc x)))
          ((lambda (x) (inc (inc x))) a)))
       ((lambda (a)
          ((lambda (x) (inc (inc x)))
           ((lambda (x) (inc (inc x))) a))) b))) c))) 5)

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (b)
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a)))
     ((lambda (a)
        ((lambda (x) (inc (inc x)))
         ((lambda (x) (inc (inc x))) a))) b))) 5))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (a)
    ((lambda (x) (inc (inc x)))
     ((lambda (x) (inc (inc x))) a)))
  ((lambda (a)
     ((lambda (x) (inc (inc x)))
      ((lambda (x) (inc (inc x))) a))) 5)))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (a)
    ((lambda (x) (inc (inc x)))
     ((lambda (x) (inc (inc x))) a)))
  ((lambda (x) (inc (inc x)))
   ((lambda (x) (inc (inc x))) 5))))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (a)
    ((lambda (x) (inc (inc x)))
     ((lambda (x) (inc (inc x))) a)))
  ((lambda (x) (inc (inc x)))
   (inc (inc 5)))))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (a)
     ((lambda (x) (inc (inc x)))
      ((lambda (x) (inc (inc x))) a)))
   (inc (inc (inc (inc 5))))))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (x) (inc (inc x)))
      ((lambda (x) (inc (inc x))) (inc (inc (inc (inc 5)))))))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 ((lambda (x) (inc (inc x)))
      (inc (inc (inc (inc (inc (inc 5))))))))

((lambda (b)
   ((lambda (a)
      ((lambda (x) (inc (inc x)))
       ((lambda (x) (inc (inc x))) a)))
    ((lambda (a)
       ((lambda (x) (inc (inc x)))
        ((lambda (x) (inc (inc x))) a))) b)))
 (inc (inc (inc (inc (inc (inc (inc (inc 5)))))))))

((lambda (a)
   ((lambda (x) (inc (inc x)))
    ((lambda (x) (inc (inc x))) a)))
 ((lambda (a)
    ((lambda (x) (inc (inc x)))
     ((lambda (x) (inc (inc x))) a))) (inc (inc (inc (inc (inc (inc (inc (inc 5))))))))))

((lambda (a)
   ((lambda (x) (inc (inc x)))
    ((lambda (x) (inc (inc x))) a)))
 ((lambda (x) (inc (inc x)))
   ((lambda (x) (inc (inc x))) (inc (inc (inc (inc (inc (inc (inc (inc 5))))))))))) 

((lambda (a)
   ((lambda (x) (inc (inc x)))
    ((lambda (x) (inc (inc x))) a)))
 ((lambda (x) (inc (inc x)))
   (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc 5)))))))))))) 

((lambda (a)
   ((lambda (x) (inc (inc x)))
    ((lambda (x) (inc (inc x))) a)))
 (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc 5)))))))))))))

((lambda (x) (inc (inc x)))
 ((lambda (x) (inc (inc x))) (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc 5))))))))))))))

(inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc (inc 5))))))))))))))))

결론: double에 double을 적용하면 제곱으로 늘어남. (((double (double (double double))) inc) 0) ;; => 256

저작자 표시 비영리
신고

티스토리 툴바