lua-users home
lua-l archive

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


>>>>> "Eduardo" == Eduardo Bart <edub4rt@gmail.com> writes:

 Eduardo> For a long time I've used the following example to benchmark
 Eduardo> tail calls in Lua 5.1, 5.2, 5.3 and LuaJIT.

 Eduardo> ```
 Eduardo> local function ack(m, n)
 Eduardo>   if m == 0 then
 Eduardo>     return n + 1
 Eduardo>   end
 Eduardo>   if n == 0 then
 Eduardo>     return ack(m - 1, 1)
 Eduardo>   end
 Eduardo>   return ack(m - 1, ack(m, n - 1))

The inner ack() in this expression is not a tail call. So you need
enough available stack to cope with the number of times it will recurse
through this specific path.

The difference in 5.4 is that Lua-to-Lua function calls now consume
space on the C stack (for a stack frame of luaV_execute), which was not
the case in earlier versions.

-- 
Andrew.