title: Why do I get "stack level too deep" with recursion?
body: <p>I have this ruby code:</p>
  
  <pre><code>def get_sum n
      return 0 if n&lt;1
    (n%3==0 || n%5==0) ? n+get_sum(n-1) : get_sum(n-1) #continue execution
  end 
  
  puts get_sum 999
  </code></pre>
  
  <p>Seems to be working for values up until <code>999</code>. When I try <code>9999</code> it gives me this:</p>
  
  <pre><code>stack level too deep (SystemStackError)
  </code></pre>
  
  <p>So, I added this:</p>
  
  <pre><code>RubyVM::InstructionSequence.compile_option = {
    :tailcall_optimization =&gt; true,
    :trace_instruction =&gt; false
  }
  </code></pre>
  
  <p>but nothing happened. </p>
  
  <p>My ruby version is:</p>
  
  <pre><code>ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]
  </code></pre>
  
  <p>I also increased the machine's stack size <code>ulimit -s 32768</code> which I think is 32MB?</p>
  
  <p>I don't think it is my code's fault as it works with smaller numbers, and I don't think <code>9999</code> is a big number.  I have 8GB of RAM and I think it is more than enough. Any ideas/help?</p>