Find limit of recursion: Difference between revisions

Content added Content deleted
(Added ZX81 BASIC)
m (→‎{{header|Lua}}: mention Lua's proper tail call)
Line 1,293: Line 1,293:


=={{header|Lua}}==
=={{header|Lua}}==
Lua (version 5.3) support proper tail call, if the recursion is proper tail call there is no limit.
Otherwise, it is limited by stack size set by the implementation.
<lang Lua>
<lang Lua>
counter = 0
local c = 0
function Tail(proper)

c = c + 1
function test()
if proper then
print("Depth:", counter)
if c < 9999999 then return Tail(proper) else return c end
counter = counter + 1
test()
else
return 1/c+Tail(proper) -- make the recursive call must keep previous stack
end
end
end


local ok,check = pcall(Tail,true)
test()
print(c, ok, check)
c=0
ok,check = pcall(Tail,false)
print(c, ok, check)
</lang>
</lang>
{{out}}
<pre>
9999999 true 9999999
333325 false D:\00EXE\share\lua\5.3\test.lua:57: stack overflow
</pre>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==