(require "numbers.BRU") (define (power base exponent) (let loop ((rest exponent) (result 1) (squaring base)) (if (zero? rest) result (loop (quotient rest 2) (if (odd? rest) (* result squaring) result) (* squaring squaring))))) ;Q: What happens when the base is zero and the exponent is non-positive? ;A: If the base is zero and the exponent is negative, evaluating the expression is an error, but an implementation of Scheme is not required to report it. When such an error occurs, some implementations of Scheme interrupt the program and produce an error message; others simply return zero as the result of the expression and keep going, even though this is mathematically incorrect. ;A: If both the base and the exponent are zero, the Scheme standard specifies that that result should be 1, although not all Scheme implementations conform to this specification.