title: Use of recursion in Scala when run in the JVM
body: <p>From searching elsewhere on this site and the web, tail call optimization is not supported by the JVM. Does that therefore mean that tail recursive Scala code such as the following, which may run on very large input lists, should not be written if it is to run on the JVM?</p>
  
  <pre><code>// Get the nth element in a list    
  def nth[T](n : Int, list : List[T]) : T = list match {
              case Nil =&gt; throw new IllegalArgumentException
              case _ if n == 0 =&gt; throw new IllegalArgumentException
              case _ :: tail if n == 1 =&gt; list.head
              case _ :: tail  =&gt; nth(n - 1, tail)
  }
  </code></pre>
  
  <p>Martin Odersky's Scala by Example contains the following paragragh which seems to suggests that there are circumstances or other environments where recursion is appropriate:</p>
  
  <blockquote>
    <p>In principle, tail calls can always re-use the stack frame of the calling
    function. However, some run-time environments (such as the Java VM) lack the
    primitives to make stack frame re-use for tail calls efficient. A production quality
    Scala implementation is therefore only required to re-use the stack frame of a di-
    rectly tail-recursive function whose last action is a call to itself. Other tail calls might
    be optimized also, but one should not rely on this across implementations.</p>
  </blockquote>
  
  <p>Can anyone explain what this middle two sentences of this paragraph mean?</p>
  
  <p>Thank you!</p>