[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why tail recursion matters and why Java isn't it, was Re: lispperformance was Re: problems with lisp

>>>>> "Pascal" == Pascal Costanza <costanza@iai.uni-bonn.de> writes:

Pascal> Michael Sperber wrote:

Pascal> In Scheme you're relying on a very specialized feature of tail
Pascal> calls to be sure that your code is efficient.

Tail recursion is a pretty fundamental semantic property, and it sure
isn't about "efficiency."  (And, as such, it's anything but
specialized.)  I'll leave it to Shriram to yell at you some more :-)

Pascal> Why should it be important to cover all cases? 

Because you may not be able to write the program you need if you

As Matthias explained (and as you don't seem to've read), iteration
and recursion are about fundamental properties of the underlying data
and the nature of what you're trying to compute.  Once you understand
that, all programs follow their data structures in a (truly)
straightforward fashion.

>> ... and, of course, I can't resist pointing out that iteration is a
>> special case of recursion.  So the terms you use are inappropriate.
>> Matthias is talking about *looping constructs*, not iteration.
>> Recursion is not always the most "natural" the solution---in the
>> spectrum you describe, it's always the *only* solution.

Pascal> I disagree. Programming language design should not be purely based on
Pascal> the mathematical aesthetics of simplicity and generality. Programmer's
Pascal> convenience is also important.

This isn't anything to agree or disagree on: It's a fact.  Exposing
iteration in a form that doesn't utilize explicit calls (looping
forms, that is) is a different matter.  You need to adjust your use of

Pascal> In my example, what I want is to collect the cars of all elements in a
Pascal> list. I simply don't care whether this is achieved by iteration, by
Pascal> recursion, or by sending a rocket to Mars and blowing it up. And the
Pascal> LOOP implementation explicitly tells me: "for all elements in the
Pascal> list, collect their cars." How can this be any clearer?

By explaining what you mean by "collect."  And by writing down the
order of the collection.  Try writing down solutions where the
accumulating operation isn't cons, but, say +, and, or -.  This should
be a matter of simple replacement, right?

Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla