What is TCO?

Tail-calling, or tail recursion, is a functional programming technique by which a function calls a subroutine function as its final procedure before returning control to its own caller. Direct recursion occurs when a function calls itself recursively. Recursion is mutual, or indirect, if a function calls another function which, in turn, calls the original function.

Thus, for example, when a function tail-calls itself, it stacks itself over and over again until a certain condition is met, at which point it will definitely return, thus effectively popping the entire call stack.

Optimizing tail-calls consists of popping the current function from the call stack before performing the tail-call and keeping the current function's caller ...

Get Mastering The Faster Web with PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.