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.


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