Subject: Re: When would it be better to use recursion than a loop?
From: Erik Naggum <erik@naggum.no>
Date: 2000/03/30
Newsgroups: comp.lang.lisp
Message-ID: <3163396794300015@naggum.no>

* Flounder <japh@flashmail.com>
| I come from a background of C/C++, perl, python, and more languages of
| the sort.  I am currently learning Lisp on my own and am seeing that Lisp
| programmers use recursion more than I have seen in the other languages
| that I have programmed in so when is it best to use it and when would it
| be best to use loops?  Maybe you could just give me some basic rules to
| follow on how to decide which to use.

  here's my rule of thumb: whenever the algorithm generates values from or
  for each iteration, it is naturally recursive, and will most probably
  find an elegant recursive expression, which, because it uses an optimized
  storage of such values, namely the function call stack frame, will also
  be more efficient than your hand-crafted storage unless you're very good
  at what you're doing.  whenever the algorithm does _not_ generate values
  from each iteration (as in: generates and consumes an equal amount of
  values), it is in my not so humble opionion extremely unlikely that a
  recursive implementation will make more sense than an iterative solution,
  and not unlikely that a recursive solution will be more complex and will
  also run slower unless you're careful.

#:Erik