3 ms·
Recursion can be expensive (call stack) depending on the language implementation. For example Lua 5.1 and recent JS implementations have a proper recursive tai
by frik 11y ago
Recursion can be expensive (call stack) depending on the language implementation.
For example Lua 5.1 and recent JS implementations have a proper recursive tail call implementation. The Lua manual explains it:
"Without proper tail calls, each user move would create a new stack level. After some number of moves, there would be a stack overflow. With proper tail calls, there is no limit to the number of moves that a user can make, because each move actually performs a goto to another function, not a conventional call." -- http://www.lua.org/pil/6.3.html http://www.lua.org/pil/6.3.html