lua-users home
lua-l archive

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


Nathan Linger wrote:
[...]
> Due to Lua's proper tail recursion, I expected the two to be
> operationally equivalent, but the functional version causes a stack
> overflow!

Lua only does tail recursion for statements of the form:

return functionname(arguments...)

In your case, you're doing:

return {argument, functionname()}

In order for Lua to be able to construct the table to return, it's got
to push its contents onto the stack... which means it's got to call
functionname() as a fully-fledged function call.

Sorry.

-- 
+- David Given --McQ-+ "If you're up against someone more intelligent
|  dg@cowlark.com    | than you are, do something insane and let him
| (dg@tao-group.com) | think himself to death." --- Pyanfar Chanur
+- www.cowlark.com --+