exercise-18.scm (449B)
1 (define-library (sicp solutions chapter-1 exercise-18) 2 (import (scheme base)) 3 (export fast-*-iterative) 4 5 (begin 6 (define (double x) (* 2 x)) 7 (define (halve x) (/ x 2)) 8 9 (define (fast-*-iterative a b) 10 (define (f result a b) 11 (cond 12 ((= b 0) result) 13 ((even? b) (f result 14 (double a) 15 (halve b))) 16 (else (f (+ result a) a (- b 1))))) 17 (f 0 a b))))