Tail Call Optimisation in Common Lisp Implementations

While the Common Lisp standard does not require implementations to eliminate tail calls, some do—thereby allowing a more functional programming style. Especially in the prototyping phase, it can be useful to know where this functional style can be employed and where it's likely to cause stack overflow. Since I couldn't find a single document outlining support for tail call optimisation, I've written it.

In what follows, I distinguish between Tail Call Optimisation (TCO)—where all calls in tail position are optimised into jumps—and Tail Self-Call Optimisation, a special case of TCO where only self-calls are optimised (this is usually what people want when they refer to TCO as it allows for the recursive style). TCO is sometimes referred to as proper tail recursion.

This document is still incomplete; feedback would be appreciated (especially where claims are just outright wrong!).

Nice to haves: [0/2] [ ] Demonstration of trampoline code; [ ] Discussion of optimisation declarations and their effects on each implementation.



1 Findings The following implementations were found to provide full TCO: CMUCL

SBCL

CCL

Allegro

LispWorks …only optimise self-calls in tail position: CLisp

GCL

ECL (when explicitly compiled) …neither: ABCL General points: Allegro's documentation is the most explicit.

Most (if not all) explanations refer to disassembly listings for demonstration. YMMV.