title: work around stack overflow error when going through recursive function 300+ times in groovy?
body: <p>I have the following code, trying to find the first number of the Fibonacci sequence with over 1000 digits:</p>
  
  <pre><code>z = 0g
  def fib
  fib = {a,b-&gt; 
      if(a &lt;= 10g**1000){
          z++ 
          fib(b.toBigInteger(), (a+b).toBigInteger())
      }else{
          return z
      }
  }
  
  fib(1,2)
  </code></pre>
  
  <p>This function works when I change "1000" to ~300 or less, and it computes in well under a half a second.</p>
  
  <p>However, when I raise the variable above that, I get a stack overflow. I saw another question about this and the answer was to use a function called "doall," but I don't see that in Groovy.</p>
  
  <p>I figure the solution is pretty simple at this point, but I don't know where to look for it...</p>
  
  <p>Can anyone help me out?</p>
  
  <p>Thanks so much!</p>