How can Ruby's recursion be 'sabotaged' to disable the ability of ruby methods to engage in recursion?
Needed for the creation of a program to teach lambda calculus, but using Ruby.
Motivation from Crockford on JavaScript - https://www.youtube.com/watch?v=ya4UHuXNygM&feature=youtu.be&t=1h9m53s
You can use the
TracePoint
API to trace all method calls and returns and build a stack to see whether a method that is called is already on the stack. That way, you can at least detect recursion, and then you can justraise
an exception orexit
the program.Something like:
Note that I stuck a debug
p
rint in there so that you can observe how it works: