2 ms·
Loops in general are a problem. Tail-Recursive functions would be a far better solution. And almost every loop can be replaced with a simple map, fold, or fil
by kuschku 12y ago
Loops in general are a problem.
Tail-Recursive functions would be a far better solution.
And almost every loop can be replaced with a simple map, fold, or filter.
- frik 12y agoRecursion 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