title: Scheme operation performed recursively instead of only once
body: <p>I'm trying to find the distance between two points in 3D space:</p>
  
  <p>Here is my code: </p>
  
  <pre><code>(define (helper p1 p2)
      (if (null? p1)
          0
          (+ (distTo3D (cdr p1) (cdr p2))
             (expt (- (car p1) (car p2)) 2))))
  
  (define (distTo3D p1 p2)
      (sqrt (helper p1 p2)))
  </code></pre>
  
  <p>I thought that defining a helper might make it so that <code>sqrt</code> is only called on the element that is returned at the end of the helper function. However given a call such as this:</p>
  
  <pre><code>(distTo3D '(1 1 1) '(2 2 2))
  </code></pre>
  
  <p>It returned the wrong answer. After experimenting for a while I saw that it was returning <code>sqrt(sqrt(1) + sqrt(2))</code> as if the sqrt was a part of the recursive statement itself.</p>
  
  <p>How can I alter my code such that it only calls sqrt on the last element returned by helper?</p>