Trampoline Pattern: Iterative Execution of Thunks

The trampoline pattern in Python and Java transforms deep recursion into iteration by having functions return callable 'thunks' (objects representing the next computation step) to an outer loop, which then iteratively executes them, ensuring constant stack depth.

Sources

Open the full topic