4 ms·
> Tail-recursions are the exact equivalent of loops. Not necessarily. In the common case of a procedure calling itself a loop does wind up being equivalent. OT
by malisper 12y ago
> Tail-recursions are the exact equivalent of loops.
Not necessarily. In the common case of a procedure calling itself a loop does wind up being equivalent. OTOH with mutually recursive procedures (two or more procedures which call each other), there is no straightforward way to convert the tail calls into a loop.
- mihai_ionic 12y agoIs there any reason why something like the following should not work? while (condition) { a(); if (!condition) break; b(); }
- malisper 12y agoYour example assumes that you can inline the calls to a and b. If you can't (for example if one of them calls themselves) then your optimization won't work.