4 ms·
I experimented with something similar to this way back[1], but took a slightly different approach - you can replace the reference to the function itself inside
by orf 9y ago
I experimented with something similar to this way back[1], but took a slightly different approach - you can replace the reference to the function itself inside the function with a new function[2], one that returns a 'Recurse' object. That way it looks like it's calling the original method but really it's doing your own thing.
1. https://tomforb.es/adding-tail-call-optimization-to-python/ https://tomforb.es/adding-tail-call-optimization-to-python/
2. https://gist.github.com/orf/41746c53b8eda5b988c5#file-tail_call-py-L16 https://gist.github.com/orf/41746c53b8eda5b988c5#file-tail_c...