title: Scheme - Replacing elements in a list with its index
body: <p>I am trying to replace the elements in a scheme list with its position.
  For example, calling: </p>
  
  <pre><code>(position '((a b) c))
  </code></pre>
  
  <p>should return:</p>
  
  <pre><code>'((0 1) 2)
  </code></pre>
  
  <p>So far, my code keeps the list format, but the index is not updating.</p>
  
  <pre><code>(define (position term1)
    (define index 0)
      (cond [(null? term1) '()]
            [(list? term1) (cons (position (car term1)) (position(cdr term1)))]
            [else (+ 1 index) index]))
  </code></pre>
  
  <p>When <code>(position '((a b) c))</code> is called, it returns</p>
  
  <pre><code>'((0 0) 0)
  </code></pre>
  
  <p>Can anybody explain why the index isn't updating?</p>