[Jprogramming] Tail recursion (bug hijack)
Dan Bron
j at bron.us
Sat Mar 19 18:39:13 UTC 2016
Louis wrote:
> The problem is that u^:v^:_ y terminates
> either when 0 = v y OR when y -: u y .
Yeah, this has bitten us all at one time or another. The traditional solution is to add a little tag to the data structure which you mutate (along with the normal processing) at every iteration. Most commonly we just do (u@:>@:{. ; -.&.>@:{:)^:v^:_ y ; 0 (adjusting the boxing logic as needed).
I asked for better alternatives than this a few years back [1], but we didn’t come up with anything compelling.
-Dan
[1] J Programming thread, “Limit limitation, Oct 2009:
http://www.jsoftware.com/pipermail/programming/2009-October/016513.html <http://www.jsoftware.com/pipermail/programming/2009-October/016513.html>
More information about the Programming
mailing list