Re: Iteration in lisp



On Apr 21, 8:45 pm, w...@xxxxxxxxxxxxxxx (Bob Felts) wrote:
Kent M Pitman <pit...@xxxxxxxxxxx> wrote:

"rig...@xxxxxxxxx" <rig...@xxxxxxxxx> writes:

If you want to iterate through a list, should you use a recursive
function or a loop?

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.

Any pointers to the rationale for this decision?

This isn't rationale for that decision, but look through January
archives of this newsgroup for the TAILPROG macro, by which I show
that tail recursion is just syntactic sugar for goto, and portable
tail recursion with syntax resembling FLET or LABELS can be obtained
from a fairly simple, small macro.
.



Relevant Pages

  • Re: Iteration in lisp
    ... recursive function can run out of stack since CL does not guarantee ... In loop you would usually only need one change. ... So using tail recursion rather than a loop can introduce bugs in complex looping constructs. ...
    (comp.lang.lisp)
  • Debug my program please.
    ... I have an error in to recursive function aggiungiat first recursion. ... !character,allocatable:: Parola ... Reinizializzazione della parola if (.not. ...
    (comp.lang.fortran)
  • Re: Tail recursion
    ... Recently I read about "tail recursion" - ability of ... programming language realization to convert linear recursive proccess ... to linear iterative proccess. ...
    (comp.compilers)
  • Re: Timing Rescordset
    ... The recursive function I am using first check to see if it has something, ... avoid levels of recursion that lack substantial advantage. ... XML authors use the same node name in a different heirarchy? ... To reconstruct, you'll have to query the db for each level, in much the same ...
    (microsoft.public.data.ado)
  • Re: How to make mod_lisp faster than php?
    ... In the Lisp group, the first fellow will answer, "I know my opinion, ... There seem to be various levels of acceptance of deep recursion ... It's possible that Scheme is here because a standard implementation of call/cc which puts stack frames on the heap yields this property. ... I think that implies tail recursion, ...
    (comp.lang.lisp)