title: How to write a power function in Lisp(scheme)? What's wrong with my program here?
body: <pre><code>(define (pow b n) 
      &quot;YOUR-DOC-HERE&quot;
      (cond ((= n 0) 1)
            ((even? n) (pow (pow b (/ n 2)) 2))
            ((odd? n) (* b (pow (pow b (/ (- n 1) 2)) 2)))))
  
  
  (define (pow b n) 
      &quot;YOUR-DOC-HERE&quot;
      (cond ((= n 0) 1)
            ((even? n) (* (pow b (/ n 2)) (pow b (/ n 2))))
            ((odd? n) (* b (pow b (/ (- n 1) 2)) (pow b (/ (- n 1) 2))))))
  </code></pre>
  <p>Here are two versions of my code for a power function with logarithmic efficiency. However, the first function would have a <code>maximum recursion depth exceeded</code> error and the second, though works, doesn't seem to function at a required efficiency. I am new to Scheme and I wonder what's wrong with these implementations?</p>