How to use "over" on 2 lists of inputs, each time picking 1 element from the 2 lists?
E.g., there is:
(+/)[1;2 3] = +[+[1;2];3] = 6
How to do something like:
f:{x+y+z};
(f/)[1;2 3;22 33] = f[f[1;2;22];3;33] = 61
Thank you.
How to use "over" on 2 lists of inputs, each time picking 1 element from the 2 lists?
E.g., there is:
(+/)[1;2 3] = +[+[1;2];3] = 6
How to do something like:
f:{x+y+z};
(f/)[1;2 3;22 33] = f[f[1;2;22];3;33] = 61
Thank you.
"over" takes two arguments each time, so three arguments is not an option: http://code.kx.com/q/ref/control/#over
To achieve what you have mentioned, the function as well as the input have to be twisted:
f:{x+y[0]+y[1]}
(f/)1,flip(2 3;22 33)
This should work exactly as you described, which is the fold behaviour of over /
. When using it with 3 arguments the function cycles through lists of y
and z
applying them to the output of the previous expression. Considering the numbers you have provided:
x:1
y:2 3
z:22 33
The wiki page describes this as:
f[f[… f[f[x;y0;z0];y1;z1]; … yn-1;zn-1];yn;zn]
Which is pseudocode looks something like:
res = x + y[0] + z[0] // pass this value forward
= res + y[1] + z[1]