title: When to use auxiliary recursive functions/methods for recursive functions/methods
body: <p>In a worksheet for a functional programming course, I was asked to write a function in Scala (though I think the prof may have meant method) that recursively prints elements in a list on a new line with a line number with a result like this:</p>
  
  <pre><code>    scala&gt; printCounter (List ("the", "rain", "in", "spain"))
  [001] the
  [002] rain
  [003] in
  [004] spain
  </code></pre>
  
  <p>The solution provided on the worksheet looks like this:</p>
  
  <pre><code>def printCounterAux [X] (xs:List[X], count:Int) : Unit = {
    xs match {
      case Nil   =&gt; ()
      case y::ys =&gt; {
        println ("[%03d] %s".format (count, y))
        printCounterAux (ys, count + 1)
      }
    }
  }
  
  def printCounter [X] (xs:List[X]) : Unit = {
    printCounterAux (xs, 1)
  }
  
  printCounter (List ("the", "rain", "in", "spain"))
  </code></pre>
  
  <p>It had not occurred to me to create an auxiliary method. My question, as someone who is still getting a handle on recursion, is: how do you know when it is necessary to create an auxiliary recursive method? In this case would the signal be multiple parameters? Or is it simply a matter of lots of exposure to these kinds of methods? Thanks very much for any advice you can share. Cheers.</p>