1

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.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
iwbabn
  • 1,275
  • 4
  • 17
  • 32
  • 4
    Over behavior is exactly same as you mentioned in both of your examples and will give you the expected results. What problem are you facing in that? – Rahul Aug 14 '16 at 21:57

2 Answers2

0

"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)
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Charles Lin
  • 624
  • 1
  • 5
  • 5
  • There are some differences in over and '/' (slash ) behavior . Slash can work with multivalent function when used as over. check http://code.kx.com/wiki/Reference/Slash – Rahul Aug 25 '16 at 08:58
0

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]
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36