Consider the following, which computes the successive cross products 0 cross 0
(1 result), then 0 1 cross 0 1
(4 results), then 0 1 2 cross 0 1 2
(9 results):
f=. (<@,"0/~&i.)"0
f 1+i.3
which outputs:
┌───┬───┬───┐
│0 0│ │ │
├───┼───┼───┤
│ │ │ │
├───┼───┼───┤
│ │ │ │
└───┴───┴───┘
┌───┬───┬───┐
│0 0│0 1│ │
├───┼───┼───┤
│1 0│1 1│ │
├───┼───┼───┤
│ │ │ │
└───┴───┴───┘
┌───┬───┬───┐
│0 0│0 1│0 2│
├───┼───┼───┤
│1 0│1 1│1 2│
├───┼───┼───┤
│2 0│2 1│2 2│
└───┴───┴───┘
Sometimes what we really want is the combined result, that is:
f=. [: (#~~:&a:) [: , (<@,"0/~&i.)"0
f 1+i.3
which outputs:
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│0 0│0 0│0 1│1 0│1 1│0 0│0 1│0 2│1 0│1 1│1 2│2 0│2 1│2 2│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
The fundamental problem is that because each number outputs a different number of results (1, 4, 9, etc), we must arrive at our answer via the circuitous route of getting results with fill, only to immediately flatten and filter away that same fill.
Can we solve this with a reduction?
Another approach would be to think of this process as a reduction, which seems promising (no fill / filter) when we try it with 2 arguments:
(,/&([: ,/ ,"0/~&i.))/ 1 2
which outputs:
0 0 NB. <- result of left arg
0 0 NB. \
0 1 NB. \ these 4 result of right arg
1 0 NB. /
1 1 NB. /
However, if we try to reduce with a list of 3 or more elements, we'll get an error because after the first rightmost evaluation, the right argument will no longer be an atom, but the table result (ie, the result above) of the verb applied to the first 2 elements.
We can attempt to avoid this by applying our transformation only to one argument, say the left argument, but then the very last argument won't be processed:
(([: ,/ ,"0/~&i.)@[ , ])/ 1 2 3
which outputs:
0 0
0 0
0 1
1 0
1 1
3 3 NB. almost, but woops: the rightmost argument was not expanded
The question is: Is there a solution to the problem of combining results of different shapes in a single calculation, without filling and filtering?