lua-users home
lua-l archive

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


Duncan Cross wrote:
On Fri, Jul 18, 2008 at 6:26 AM, Mike Crowe <> wrote:

2)  I ran across something about tail calls, or tail recursion, does that

You can use tail calls to approximate state machines, but it will mean
the system is no longer asynchronous in the same way and will run
until the terminating state is hit, unless you make use of coroutines.
It also doesn't help with your meaningful-names-for-debugging problem.
It does mean that you can use arbitrary arguments appropriate for the
state instead of always a single data argument, however.

"Tail calls make debugging hard" is the argument of the Python crowd for not implementing them. This is not true because when using tail calls one must pass the complete "state" of the algorithm as the current function will be removed from the stack. To debug, study the state.

Tail calls mean that one of these states could return with a call to
itself, an unlimited number of times, without overflowing the stack.

     Lua optimise all tail calls, not only tail recursion.