I believe that i. stops at the first match. So this should work. ({.~0 i.~])4 3 2 8 0 9 1 4 3 2 8
On Wed, Jan 15, 2020, 2:08 PM Julian Fondren <jfond...@minimaltype.com> wrote: > On Wed, 2020-01-15 at 22:58 +0300, 'Sergey Kamenev' via Programming > wrote: > > Hi! > > > > I need test function f on array x1 x2 ... xn > > > > If f(x) = 0 then no need test another member of array. > > So, you want the member of an array that passes a test, and you don't > want to apply the test to the entire array. I'm still learning J, but > this works: > > until =: 1 : '([: $: }.)`{.@.([: x&-: [: u {.) y' > 25 *: until i.10 > 5 > 1 >&5 until i.10 > 6 > > On the LHS of @. are two gerunds: a recursion over the tail of the > list, and a verb to get the head of the list. On the RHS is a test > against the head of the list. As long as that test fails, it's tested > against later elements of the list, and finally when the test succeeds, > the head of the list is returned. > > > example =: monad : 0 > > for_i. a do. > > if. 25 = f i do. > > i return. > > end. > > 0 > > end. > > ) > > So you also want a 0 on failure? You can get that with :: as eventually > the recursion will run out of list. > > 25 *: until 1 2 3 4 > |stack error > | ([:$:}.)`{.@.([:x&-:[:u{.)y > 25 (*: until :: 0) 1 2 3 4 > 0 > 25 (*: until :: 0) 5 > 5 > > > example a > > > > Nice day! > > Sergey > > > > > > > > ------------------------------------------------------------------- > > --- > > 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