Re: Iteration in lisp



On Apr 21, 8:34 pm, 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.  Anyone who tells you otherwise is living in a
fantasy world or is telling you something implementation-dependent or
is confusing Lisp with Scheme.

Even if you have tail recursion, you are still wasting productivity by
writing your own list iteration instead of using the existing library
functions.
.



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)
  • Re: Javascript recursion limit
    ... a loop is something that repeats - that comes back to the ... An recursive function can do that, if the language allows it. ... ECMAScript does not require an implementation to have tail recursion, ...
    (comp.lang.javascript)
  • Re: do expression
    ... assignments be executed during execution of the do loop ... do (funcall g th2) ... the Common Lisp version above is incorrect. ... What needs to be done in a translation of binding semantics to assignment semantics is that new local bindings are created manually in each iteration, so that they can persist, and that all references go to those local bindings. ...
    (comp.lang.scheme)
  • Re: Common Lisp implementations are still multiple times slower than C
    ... In another thread in this newsgroup some people wrote that Common Lisp can ... Java compiler to create an efficient version. ... (loop for y from 0 below height ... (if (zerop cell) ...
    (comp.lang.lisp)
  • Re: Why Im giving up on Lisp for now
    ... >> Over the last few months I've made an effort to learn Common Lisp, ... >> never work first time, and I have to experiment with quotes, ... > Macros can be tricky. ... loop takes two minutes instead of two seconds. ...
    (comp.lang.lisp)