CL Implementations and Tail-Call Elimination



Every once in a while, a newbie comes along working through a problem
where they use recursion to do iteration, and usually one of the first
things anyone suggests is that they switch over to using DOLIST or
LOOP or something. In and of itself, this is perfectly good advice,
but one of the reasons always cited (and I cite it too) is that you
can't rely on an ANS Common Lisp implementation to eliminate tail
calls, the way you can rely on a Scheme implementation to do that.

However, it looks to me like CL implementations really usually will do
that sort of elimination, at least with the right set of declarations.
So I'm sort of wondering which common Common Lisps don't do that. I
blithely rely on it since SBCL does it, and I want to know whether
this is a mildly bad habit or a really bad habit, at least from a
portability standpoint.

Cheers,
Pillsy

.



Relevant Pages

  • Re: Newbie style questions
    ... It is also, in Common Lisp, also a subtly bad example. ... implementation of the SORT algorithm. ... It varies with the task and the preferences of the programmer. ... which is why some people prefer iteration. ...
    (comp.lang.lisp)
  • Re: Mutable reference to a structure field
    ... > I take your point about recursion/iteration. ... > iteration is because it's really no more difficult in this case, ... > it is a shame that there doesn't appear to be one in Common Lisp. ... programming language" and Graham's Lisp-DNA comparison. ...
    (comp.lang.lisp)
  • Re: Lexical closures - difference between Common Lisp and Scheme
    ... this way to compare with Python and Perl. ... In Common Lisp, the same: ... anonymous function you are referencing i. ... Alternatively one could have a different i on each iteration step ...
    (comp.lang.lisp)
  • Re: Recursive procedure vs. recursive process in CL
    ... - Linear Recursion and Iteration. ... even if the iterative process is described by a recursive procedure. ... but how is it with Common Lisp? ...
    (comp.lang.lisp)
  • Re: Idiomatic lisp - loops
    ... Is a program that needs real speed on large data sets really using dotted pairs in a list as the data structure? ... If what he really wanted was a tutorial on how to write clever schemisms in common lisp, then, hey, go to town with labels and the rest. ... It provides a means of adding an element to an existing list and a means to stably sort an existing list destructively, which takes not one, but two functional arguments for customization. ...
    (comp.lang.lisp)