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 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

Conjunctions have long left scope.

You don't need +/, just use # - as you could with my original verb.

In your second bug, you are not executing 1&Z: .  You should have @: not &: .

@Mike: don't fret about performance yet - Fold is implemented in a script.  I will move it to C when the time is ripe.

Henry Rich


On 1/16/2020 4:23 AM, 'Sergey Kamenev' via Programming wrote:
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 0 0 0 0 0 0 0

Expecting:
0 0 0 0 1

2. In ideal case I expecting only one result from my function: 0 or 1.

I can realize it using your approach with +/

But this is waste computations.

I hope F.. is decision for skipping unnecessary intermediate results.
But I see same bug:

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

Expected:
1

3. About suggestion. For my mind very strange and hard current argument ordering for u in Fold.
IMHO it's contintuitive.

d =: dyad : 0
  echo x ; y
  0
)

0 d F:. ] 1 2 3

0 d F:. ] 1 2 3
┌─┬─┐
│1│0│
└─┴─┘
┌─┬─┐
│2│0│
└─┴─┘
┌─┬─┐
│3│0│
└─┴─┘
0 0 0

For my more clear order:
x - ini (previsious) value
y - value from array

┌─┬─┐
│0│1│
└─┴─┘
┌─┬─┐
│0│2│
└─┴─┘
┌─┬─┐
│0│3│
└─┴─┘
0 0 0

Thank you!
Sergey




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
----------------------------------------------------------------------
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