Re: Iteration in lisp



"John Thingstad" <jpthing@xxxxxxxxx> writes:

På Tue, 22 Apr 2008 05:34:34 +0200, skrev Kent M Pitman
<pitman@xxxxxxxxxxx>:

In Common Lisp, always prefer a loop where practical unless you know
with relative certainty that the problem cannot grow very big. A
recursive function can run out of stack since CL does not guarantee
tail call elimination. Anyone who tells you otherwise is living in a
fantasy world or is telling you something implementation-dependent or
is confusing Lisp with Scheme.

Fantasy world? Nearly all compilers seem to do tail call elimination
with the default settings.

My remarks were directed not any user making a properly informed
choice, but at someone advising ("anyone who tells you") if they do
not properly qualify their remarks as non-portable. When I speak of
Common Lisp, I generally mean "any Common Lisp"; when I want to talk about
a particular implementation, I tend to identify that.

There are a great many ways one can legitimately program if one knows
the assumptions one is making and has examined the risks. But the
language definition is what it is, and pretending it's not what it is
for the sake of easier explanation is the fantasy to which I was
referring.

I have recently remarked that I don't like the default CL treatment of
SETQ and that I tend to program in a non-portable fashion. I don't disagree
that this will create problems. I don't recommend others ignore the fact
that the standard makes this issue dicey. I think as long as people know the
truth, they can make an informed decision.
.



Relevant Pages

  • Re: CAS, Lambda Calculus, Continuation and Functional Programming
    ... >>that makes tail call elimination less attractive for compiler writers. ... > I don't know why exception handling should prevent tail-call ... so a local array would be best (in languages ...
    (sci.math.symbolic)
  • Re: Pure speed
    ... Allegro Common Lisp and LispWorks both optimize ... > tail calls when the compiler optimizations are set properly. ... I don't know what differences exist between the SBCL and CMUCL ... about TRACE not working as expected because TCO happened? ...
    (comp.lang.lisp)
  • Re: CL Implementations and Tail-Call Elimination
    ... can't rely on an ANS Common Lisp implementation to eliminate tail ... it looks to me like CL implementations really usually will do ... it forces you to compile your code in some obscure ways, ... Tail call optimization is not specified in Common Lisp. ...
    (comp.lang.lisp)
  • Re: Was not making tail recursion elmination a mistake?
    ... >> I have recently been annoyeed by the fact that tail recursion ... >> elimination and must use loops or some simular structue. ... > have been an optional feature. ...
    (comp.lang.lisp)
  • Mandatory tail call elimination (was: Needed features in upcoming standards to support VMs & lan
    ... Note that I've never written more than a toy compiler, ... Do anyone know of a language with mandatory tail call elimination but no ... An ordinary function call never has _TailCall semantics. ...
    (comp.std.c)