Tail-call optimization
Tail-call optimization is a compiler or runtime transformation that executes an eligible call in tail position without allocating an additional call-stack frame.
Functional Programming in JavaScript
A compiler optimization that reuses the current call frame for a function call in tail position instead of creating a new stack frame.
- How it is used
- Optimizes recursive iteration when changing inputs limit the usefulness of memoization.
- How deep it goes
- Explains tail position, accumulated arguments, and single-frame reuse, but does not develop broader compiler behavior.
- Examples
- Uses factorial evaluation and accumulator-based array summation to contrast ordinary and tail-recursive forms.
- What you can do after
- Apply it by converting recursive factorial or summation functions into accumulator-based tail-recursive forms.
Read how Functional Programming in JavaScript explains tail-call optimization →
Elixir in Action, Third Edition
Tail-call optimization is a compiler or runtime optimization that reuses a caller's stack frame when its final operation is a function call.
- How it is used
- Uses tail calls to implement memory-efficient recursion and arbitrarily large iterations in Elixir.
- How deep it goes
- Explains stack-frame reuse and tail-call structure, then stops short of compiler implementation details.
- Examples
- Demonstrates natural-number printing, ordinary list summation, and accumulator-based tail-recursive list summation.
- What you can do after
- Build it from scratch using an accumulator and a final recursive call to process arbitrarily large iterations.
Read how Elixir in Action, Third Edition explains tail-call optimization →
Functional Programming in Scala, Second Edition
Tail call elimination is a compiler optimization that implements eligible recursive calls without allocating a new call-stack frame for each call.
- How it is used
- Uses tail-position recursion to express loops functionally and avoid consuming one call-stack frame per iteration.
- How deep it goes
- Defines tail position, contrasts eligible and ineligible recursion, traces factorial, and extends the idea to trampolining.
- Examples
- Demonstrates accumulator-based factorial, execution traces, deeply composed identity functions, and TailRec function composition.
- What you can do after
- Evaluate whether recursive calls are in tail position and apply TailRec trampolining when direct composition risks stack overflow.
Read how Functional Programming in Scala, Second Edition explains tail-call optimization →
Related concepts
- loop-recurimplemented by · In Clojure, loop/recur is a construct that re-enters a loop or function with replacement values without growing the call stack.
- tail calluses · A tail call is a function or method call that is the caller’s final operation, with its result returned directly without further computation.
- try-catch statementcontrasts with · A try-catch statement is a control-flow construct that executes code under exception handling and transfers control to a matching handler when an exception is raised.
- recursionused by · Recursion is a computational technique in which a definition or procedure refers to or invokes the same definition or procedure, directly or indirectly.
- stack overflowaddresses · A stack overflow is a runtime failure caused by exhausting the available capacity of a program’s call stack.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


