Re: Any way to tail-recurse this?



On Wed, 22 Aug 2007 10:15:45 -0700, pineapple.link wrote:

You are now just a small step away from a tailrecursive version,
that keeps the head of the list as a separate accumulating parameter:

I am impressed with your analysis, and code contribution. However,
are you saying that the above code (the poster above you, and perhaps
my last attempt as well, albeit an uglier version) is NOT tail-
recursive? From what I have read, it seems that it should be. It
does some work and gets that stuff "out of the way," and then lastly
calls itself again.

If it is not tail-recursive, can you tell me why not?

Your version was tail-recursive.

I should have been more clear and written something like:

You are a small step away from a tailrecursive version that at
the same time keeps ... as a separate accu.

It is kind of a waste to put the accu in a datastructure - but as the
other poster noted, quite cunning.

Now that I am at it, maybe a little thing on case analysis.
if you deal with lists, there are usually only two cases: the empty list
and the non-empty list. If you think a predicate that deals with lists
needs more than these two cases, there are only the following five
possibilities:

you are wrong and need to rethink
you are wrong and need to rethink
you are wrong and need to rethink
you are wrong and need to rethink
you were right

:-)

Cheers

Bart Demoen
.