You are, almost, scarring me ;)

On Mon, Mar 21, 2016 at 10:59 AM, Raul Miller <[email protected]> wrote:

> So, ok, one issue with while loops is that they let you deal with (for
> example) markov processes. If you're doing something "random" such as
> simulation, you do not necessarily want to exit on the first
> "non-functional" result. Of course, if you were including the hidden
> variable(s) used to drive the random number generator, you would not have
> this problem. But if you are using the (?) builtin, that hidden variable
> remains hidden.
>
> One issue with while loops is the "infinite loop" issue. This is great fun
> if you like locking up your interpreter, and maybe going out for a snack
> while waiting to see if it recovers. This is less fun if you are trying to
> actually get something useful done.
>
> Recursion does not have this issue - instead, it takes down your entire
> session. Well, ok, depending on the implementation, recursion can also put
> you into an out-of-memory condition and lock up your entire OS (instead of
> just locking up the interpreter). Loads of fun here...
>
> Anyways... one practical workaround for these issues involves the use of a
> limit counter. Here, you explicitly decide to stop after some number of
> repeats. And, if you bother to include this protection, ^: does while loops
> just fine.
>
> So I guess that's the issue: do you explicitly want sloppy coding which
> under the right (or, wrong) circumstances will destroy the host
> environment? Or do you want some bit of tacit elegance?
>
> --
> Raul
>
>
> On Mon, Mar 21, 2016 at 9:54 AM, Jose Mario Quintana <
> [email protected]> wrote:
>
> > 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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to