top | item 44554046

(no title)

lapsed_lisper | 7 months ago

IDK how much this matters, but the Common Lisp standard doesn't mandate tail call elimination. So although many implementations offer it (usually as a compiler thing), it's conceptually an implementation-dependent detail that borders on a language extension: if your code actually depends on TCE for correct execution, that code might exhaust the stack under ordinary interpreter/compiler settings, and differently across different implementations. So for Common Lisp, if you want to use standardized language features standardly, it's quite reasonable to reach for iteration constructs rather than tail recursion.

discuss

order

cryptonector|7 months ago

> if your code actually depends on TCE for correct execution, that code might exhaust the stack under ordinary interpreter/compiler settings

But Lisp programmers tend to use recursion for iteration and very much count on TCO. So it really has to be implemented, and the language should require it.

Jtsummers|7 months ago

Counting on TCO is more of a Scheme thing (where the language spec guarantees it) than a Common Lisp thing. CL does not guarantee TCO so, at least historically, looping (various forms, not just the LOOP facility) was quite common.

dapperdrake|7 months ago

That is why Doug Hoyte builds NAMED-LET.

cryptonector|7 months ago

Yes, quite. In Let Over Lambda he builds a code walking named-let macro that transforms tail-recursive loops to iterative loops.