Skip to content

Instantly share code, notes, and snippets.

@fsword
Created October 12, 2012 02:25
Show Gist options
  • Save fsword/3876987 to your computer and use it in GitHub Desktop.
Save fsword/3876987 to your computer and use it in GitHub Desktop.
ruby tailcall optimization
RubyVM::InstructionSequence.compile_option = {
tailcall_optimization: true,
trace_instruction: false
}
eval <<end
def fact(n, result = 1)
if n == 1
result
else
fact(n - 1, n * result)
end
end
end
p fact(30_000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment