From: Larry Clapp
Subject: Re: Remove every atom
Date: 
Message-ID: <slrnfc42au.q43.larry@theclapp.homelinux.com>
On 2007-08-14, ·············@gmail.com <·············@gmail.com> wrote:
> I'm still new to Lisp. I've been learning Lisp for quite a while and
> still having lots of difficulties with recursion. Do you suggest any
> books, places... where I could learn more about recursion?

As far as concepts, I got a good grip on recursion when I wrote two
search routines to search a network of nodes.

The first routine went like this:

  if the current node isn't the one you're looking for,
    call search on the current node's first child node.
  If the search returns and hasn't found the answer,
    search the second child node.
  and so on

The second routine went like this:

  Add the current node to the queue
  Check all the nodes in the queue
  if you haven't found the answer,
    add all the children of all the nodes in the queue to the queue
  goto step 2

Much later I found out that these are called "depth-first search" and
"breadth-first search".  (The above description of "breadth-first
search" is not, in fact, recursive, so it may've been just the first
one that taught me about recursion. :)

There may be errors in the above pseudo-code.  Caveat coder.  :)

I also implemented a very basic READ function somewhere along the way;
that helped too.

An instructor once walked us through a non-recursive quicksort in
FORTRAN (or is it "Fortran" now?).  (He may've done the recursive
version somewhere in there, I forget.  I just remember he had a
boolean variable in the non-recursive version, and to help us
visualize, he flipped his necktie over his shoulder and back again
several times during the course of the walk-through.  Remembering
always brings both a smile of amusement and a shudder of horror. :)

So anyway, my point is, think about or implement operations on
recursive data structures, or algorithms that are naturally recursive
(like quicksort), and (possibly) then implement them non-recursively
using a loop and a stack that you keep track of yourself.

Bottom line is -- write some code.  :)  The Lispworks IDE is, in my
opinion, quite good for watching your code run.  Tracing, stepping,
breakpoints, variable inspection, the whole nine yards.

-- Larry