Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread Henry Rich
No, &: works properly.  That note is just saying that monadic &: may not be as fast as monadic @: because some special forms containing @: are not recognized for &: . You are using &: dyadically.  You ended up executing 0 (1&Z: ] ]) 1 but 0 (1&Z:) 1 executes 1&Z: 0 times (see https://code.js

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread 'Sergey Kamenev' via Programming
The bugs are yours. Thank you! In your second bug, you are not executing 1&Z: .  You should have @: not &: . Does &: not work because of this? https://code.jsoftware.com/wiki/Vocabulary/ampco The monadic use of &: is deprecated. Use @: instead. Some compounds of the form f&:g are not recogn

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread 'Michael Day' via Programming
Thanks, Henry, for reminding me that it's in a script. Given that observation,  the timing is pretty impressive! Cheers, Mike On 16/01/2020 15:40, Henry Rich wrote: Your point about the order of x and y is reasonable.  If you are thinking of F:. as a variant of u/ the order makes sense.  I wi

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread Henry Rich
Your point about the order of x and y is reasonable.  If you are thinking of F:. as a variant of u/ the order makes sense.  I will think about it, and would really like to hear considered opinion from other users. The bugs are yours.    0 *:@[ F:. ((] [ 1&Z:)&:(25&=)) 3 1 4 6 5 7 8 9 0 0 0 0 1

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread Raul Miller
On Thu, Jan 16, 2020 at 4:23 AM 'Sergey Kamenev' via Programming wrote: > But this is waste computations. Conservation of resources, to be useful, should be applied at the resource bottlenecks. Otherwise the conservation efforts tend to make the problem(s) worse. Conservation also tends to force

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread 'Michael Day' via Programming
Early days - I haven't studied the Fold family yet,  but just applying your example worries me a bit if the following is typical:    q =: i. 100    ts 6!:2 , 7!:2@] NB. compare naive (! - ie"old" J) and Fold method to locate match - might be near end of array:    r[echo ts'r =: 0 *:@[ F

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread 'Sergey Kamenev' via Programming
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 Yes. But in my case I finding result of function. And your decision requires to apply function to all elements source array. Sergey -

Re: [Jprogramming] How to write this code without loop?

2020-01-16 Thread 'Sergey Kamenev' via Programming
16.01.2020 0:42, Henry Rich:    0 *:@[ F:. ([ (1 Z: 25&=)) 3 1 4 6 5 7 8 9 9 1 16 36 25 Suggestion for improving Fold are welcomed. Great! Thank you for your hard work! You are using trick with postfiltering output result 1. I found the bug: 0 *:@[ F:. (] [ 1&Z:)&:(25&=) 3 1 4 6 5 7 8 9 0

Re: [Jprogramming] How to write this code without loop?

2020-01-15 Thread Henry Rich
   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 und

Re: [Jprogramming] How to write this code without loop?

2020-01-15 Thread Don Guinn
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 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 >

Re: [Jprogramming] How to write this code without loop?

2020-01-15 Thread Julian Fondren
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