Can't think of a reason why we wouldn't want this in the official interpreter
----- Original Message ----- From: Jose Mario Quintana <[email protected]> To: Programming forum <[email protected]> Sent: Monday, March 21, 2016 9:54 AM Subject: Re: [Jprogramming] Tail recursion (bug hijack) Right, I never saw or found a satisfactory coding of a genuine while conjunction. However, in Jx one can afford, thanks to Thomas' effective implementation of the adverb O. for the Jx interpreter, to do the unthinkable: code a genuine while conjunction recursively! That is, a conjunction wTCO such that, u wTCO v ]`($:^:(1:`u))@.v O. This is how it works for the case at hand, whileO =: v1@:(v0 wTCO (-. @: v2)) NB. power i.20 0 7 8 9 10 11 12 13 14 15 16 17 18 19 recursive i.20 0 10 11 12 13 14 15 16 17 18 19 whileO i.20 0 10 11 12 13 14 15 16 17 18 19 recursiveO i.20 0 10 11 12 13 14 15 16 17 18 19 stp=. ([ ((<;._1 '|Sentence|Space|Time|Space * Time') , (, */&.:>@:(1 2&{))@:(] ; 7!:2@:] ; 6!:2)&>) (10{a.) -.&a:@:(<;._2@,~) ]) ".@:('0 : 0'"_) Y=. i.111 stp 11 recursive Y whileO Y recursiveO Y ) ┌──────────────┬──────┬────────────┬────────────┐ │Sentence │Space │Time │Space * Time│ ├──────────────┼──────┼────────────┼────────────┤ │ recursive Y│222592│0.0475173844│10576.9896 │ ├──────────────┼──────┼────────────┼────────────┤ │ whileO Y│36992 │0.0397433474│1470.18591 │ ├──────────────┼──────┼────────────┼────────────┤ │ recursiveO Y│37376 │0.0434088376│1622.44871 │ └──────────────┴──────┴────────────┴────────────┘ On Sat, Mar 19, 2016 at 2:39 PM, Dan Bron <[email protected]> wrote: > 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> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
