Hi, I would do something like this:

   f=: +:
   cond=: 100<{:
   repuntil =: 2 : '((<:@{. , u@}.)`] @. v )^:(0<{.)^:_'
   f repuntil cond 20 1
0 32

   f repuntil cond 20 1
13 128

the first item tells you whether:

- if 0: iterations ended due to hitting the limit (first item of argument);
or

- if > 0, the condition became true.

The agenda (@.) construct is just a way of making the left verb argument to
the left-most ^: return the same twice, which triggers the end of the
iteration by ^: _ .

Good luck exploring J, it'll keep being interesting for long ;).

Best regards,

Jan-Pieter

On Tue, May 26, 2020, 12:04 'Rob Hodgkinson' via Programming <
[email protected]> wrote:

> I don’t agree, it does not proceed further.
>
>    ([x] u^:v^:_ y) will actually stop when v returns 0 (does not skip or
> continue executing)
>
> Here is a simple way to confirm this using a function f to do 2&* but
> which also uses ’smoutput’ to output to the session log (print intermediate
> results).
>
> f=: verb define
>  smoutput r=:2*y
>  r
> )
>
>    f 5
> 10         NB. Intermediate print using smoutput
> 10.        NB. Result of f
>
> Test it…
>    a=:f 5
> 5.          NB. It still prints within f via smoutput
>
> So now …
>    f^:(10>])^:3 ] 1
> 2                       }
> 4                       } Intermediates from smoutpout (f called 3 times)
> 8                       }
> 8                      NB. Result returned (ran to completion)
> f^:(10>])^:4 ] 1
> 2                       }
> 4                       } Intermediates from smoutpoutn (f called 4 times)
> 8                       }
> 16                     }
> 16                     NB. Result returned (ran to completion)
> f^:(10>])^:8 ] 1
> 2                       }
> 4                       } Intermediates from smoutput (f called 4 times)
> 8                       }
> 16                     }
> 16                     NB. Result returned (aborted, so it stopped short
> and did not proceed further)
>
> HTH, Rob
>
>
> > On 26 May 2020, at 6:40 pm, Anton Wallgren <[email protected]> wrote:
> >
> > On closer inspection, f^:v^:n doesn’t seem to work (as I want it to).
> What it does is to skip evaluation each time v y returns 0. While this
> would work in my situation, as the stopping condition would remain true, it
> would of course be unnecessary (and inefficient) to keep checking this for
> the remainder of the iterations.
> >
> > Thanks, Anton Wallgren
>
> ----------------------------------------------------------------------
> 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