(define (fib n #!optional cont) (define (fib n k) (if (< 0 n) (fib (quotient n 2) (lambda (a b) (let ((c (* a (- (* 2 b) a))) (d (+ (* a a) (* b b)))) (if (= 0 (remainder n 2)) (k c d) (k d (+ c d)))))) (k 0 1))) (if (and (exact? n) (not (negative? n)) (integer? n)) (fib n (if (default-object? cont) cons cont)) (error ":not-exact-nonnegative-integer" n 'FIB)))