Created
December 27, 2015 01:33
-
-
Save franzejr/97a0842eb11a83a05481 to your computer and use it in GitHub Desktop.
Tail Call Optimization in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RubyVM::InstructionSequence.compile_option = { tailcall_optimization: true, | |
trace_instruction: false } | |
eval<<end | |
def factorial(n, result=1) | |
if n==1 | |
result | |
else | |
factorial(n-1, n*result) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment