The following is my sample code:
def test(v)
test(v-1) if v > 0
p v
end
if i call test(11893)
it is working fine.
if i have v > 11893
, it is throwing SystemStackError
.
How to increase the limit for this error?
The following is my sample code:
def test(v)
test(v-1) if v > 0
p v
end
if i call test(11893)
it is working fine.
if i have v > 11893
, it is throwing SystemStackError
.
How to increase the limit for this error?
MRI has tail recursion optimization switched off by default. But one might turn it on:
RubyVM::InstructionSequence.compile_option = {
tailcall_optimization: true,
trace_instruction: false
}
also, the code itself must use tail recursion:
def test(v)
return unless v > 0
p v
test(v-1)
end