Shriram Krishnamurthi <email@example.com> wrote:
| "Ji-Yong D. Chung" <firstname.lastname@example.org> writes:
| > It is properly tail recursive -- it was easy to implement this. I have
| > checked the scheme stack on my interpreter, and it does not grow
| > when a function calls itself with various types of tail calls.
| That isn't enough. You should also handle tail *calls*, ie, calls to
| arbitrary procedures in tail position. That's critical for functional
And not just functional programming, but certain styles of imperative
programming as well. E.g., I often implement finite-state machines in
Scheme with a procedure per state, with state transitions implemented
as a tail call from the "current" state procedure to the "next" state
procedure. It results in a very natural, readable, and easily maintained
style of code, much nicer than the "while (state!=DONE) switch (state)"
idiom usually used in C code, which rapidly becomes totally unreadable
when the number of states or transitions gets large.
Implementing the full tail-call optimization given in R5RS's "3.5 Proper
tail recursion" is essential for the procedure-per-state style to work,
especially for long-running state machines.
Rob Warnock, 31-2-510 email@example.com
SGI Network Engineering <URL:http://reality.sgi.com/rpw3/>
1600 Amphitheatre Pkwy. Phone: 650-933-1673
Mountain View, CA 94043 PP-ASEL-IA