SICP 1.20
自信なし。
; (define (gcd a b) ; (if (= b 0) ; a ; (gcd b (remainder a b)))) ;; normal-order (gcd 206 40) ;-> (if (= 40 0) 206 (gcd 40 (remainder 206 40))) ;-> (if (= 40 0) 206 (gcd 40 6) ; call remainder ;-> (if (= 40 0) 206 (if (= 6 0) 40 (gcd 6 (remainder 40 6)))) ;-> (if (= 40 0) 206 (if (= 6 0) 40 (gcd 6 4))) ; call remainder ;-> (if (= 40 0) 206 (if (= 6 0) 40 (if (= 4 0) 6 (gcd 4 (remainder 6 4))))) ;-> (if (= 40 0) 206 (if (= 6 0) 40 (if (= 4 0) 6 (gcd 4 2)))) ; call remainder ;-> (if (= 40 0) 206 (if (= 6 0) 40 (if (= 4 0) 6 (if (= 2 0) 4 (gcd 2 (remainder 4 2)))))) ;-> (if (= 40 0) 206 (if (= 6 0) 40 (if (= 4 0) 6 (if (= 2 0) 4 (gcd 2 0))))) ; call remainder ;-> (if (= 40 0) 206 (if (= 6 0) 40 (if (= 4 0) 6 (if (= 2 0) 4 (if (= 0 0) 2 (gcd 0 (remainder 2 0))))))) ;-> 2 ;; applicative-order (gcd 206 40) ;-> (if (= 0 40) 206 (gcd 40 (remainder 206 40))) ;-> (gcd 40 (remainder 206 40)) ;-> (gcd 40 6) ; call remainder ;-> (if (= 0 6) 40 (gcd 6 (remainder 40 6))) ;-> (gcd 6 4) ; call remainder ;-> (if (= 0 2) 6 (gcd 2 (remainder 4 2))) ;-> (gcd 2 (remainder 4 2)) ;-> (gcd 2 0) ; call remainder ;-> (if (= 0 0) 2 (gcd 0 (remainder 2 0))) ;-> 2