0 *:@[ F:. ([ (1 Z: 25&=)) 3 1 4 6 5 7 8 9
9 1 16 36 25

Suggestion for improving Fold are welcomed.

Henry Rich

On 1/15/2020 2:58 PM, '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.

I don't understand how write this code loopless.

Main thing: I would avoid of waste computation of f(x) if f(x) = C found.

I think about Fold but I see only ugly decision with using global variables.

Example code for rewriting:

NB. Vector with test values
a =: 1 + i. y
f =: *:

example =: monad : 0
for_i. a do.
 if. 25 = f i do.
   i return.
 end.
0
end.
)

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

Reply via email to