title: how to change max recursion depth in Julia?
body: <p>I was curious how quick and accurate, algorithm from Rosseta code ( <a href="https://rosettacode.org/wiki/Ackermann_function" rel="nofollow noreferrer">https://rosettacode.org/wiki/Ackermann_function</a> ) for (4,2) parameters, could be. But got StackOverflowError. </p>
  
  <pre class="lang-bash prettyprint-override"><code>julia&gt; using Memoize
  @memoize ack3(m, n) =
  m == 0 ? n + 1 :
  n == 0 ? ack3(m-1, 1) :
  ack3(m-1, ack3(m, n-1))
  
  # WARNING! Next line has to calculate and print number with 19729 digits!
  julia&gt; ack3(4,2) # -&gt; StackOverflowError 
  # has to be -&gt; 2003529930406846464979072351560255750447825475569751419265016973710894059556311
  # ...
  # 4717124577965048175856395072895337539755822087777506072339445587895905719156733
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Oscar Smith is right that trying ack3(4,2) is unrealistic. This is version translated from Rosseta's C++:</p>
  
  <pre class="lang-bash prettyprint-override"><code>module Ackermann
    function ackermann(m::UInt, n::UInt) 
      function ack(m::UInt, n::BigInt)
        if m == 0
          return n + 1
        elseif m == 1
          return n + 2
        elseif m == 2      
          return 3 + 2 * n;
        elseif m == 3
          return 5 + 8 * (BigInt(2) ^ n - 1)
        else
          if n == 0
            return ack(m - 1, BigInt(1)) 
          else 
            return ack(m - 1, ack(m, n - 1))
          end
        end
      end
  
      return ack(m, BigInt(n))
    end
  end
  
  julia&gt; import Ackermann;Ackermann.ackermann(UInt(1),UInt(1));@time(a4_2 = Ackermann.ackermann(UInt(4),UInt(2)));t = "$a4_2"; println("len = $(length(t)) first_digits=$(t[1:20]) last digits=$(t[end-20:end])")
    0.000041 seconds (57 allocations: 33.344 KiB)
  len = 19729 first_digits=20035299304068464649 last digits=445587895905719156733
  </code></pre>