Tail call optimization for recursion

Community Forums/Monkey2 Talk/Tail call optimization for recursion

dmaz(Posted 2015) [#1]
Some of my earlier programs used recursion to great extent that totally bombed on mobile because of the limited stack space. so I re-did them with normal while loops instead. The code for the recursive classes were so much more elegant and smaller as well.

ECMA script 6 apparently has a solution for this and it would be sweet if Monkey 2 could get too.

http://www.2ality.com/2015/06/tail-call-optimization.html


Gerry Quinn(Posted 2015) [#2]
When I did my puzzle Detective Chess for mobile, I had to take the search tree out of recursion entirely and fake it with my own stack. The calculation method would do a fixed number of iterations (taking something on the order of half a second, which would be monitored over the first few passes), then return so that an update could be performed. It would then be called again unless it has reported finished. I always wondered whether there is a neat way to encapsulate this process in a class for chess games etc., but I never got around to trying it,

Anyway, something like that might be useful too, though it's more for a single recursive process than for general use of recursion.