If someone could explain the following I would greatly appreciate it as it is a bit counter intuitive coming from an APL background. I am trying to think in lists but a bit baffled at the moment by the length error. Thanks for any help.
q)x : (1 2 3;4 5 6;7 8 9) / 3-item list that simulates 3 x 3 matrix
q)x[3;3] / ok
0N
q)x[3;3 4] / ok
0N 0N
q)x[3 4;3 4] / would have expected (0N 0N; 0N 0N)
'length
q)x[3]
`long$()
q)x[3 4] / displays as two blank lines, is (long$();
long$())?
q)x[3 4;3] / seems simple list must be last with all atomic indexes prior?
'length
you can use x[3 4][;3 4]
as far as i can tell the casting to an empty long list is done after the indexing.
so x[3 4;3 4] produces an error as x[3 4] is first a internal null value not yet casted to an empty long list.
Thanks for the reply. Not sure I understand what you mean by x[3 4] is first an internal null not yet casted. You mean the intermediate result is a 2-item list of typeless empty lists?
The workaround seems to be a kinda cool identity I haven’t seen. Thanks.
Hi, let me see if I can help. My answers are inline:
Hi Tiago,
The only problem is that indexing at depth and indexing with a nested list produce very different results. Let me demonstrate with a non-null case:
q)x[0 1;1 2]
2 3
5 6
q)x[(0 1;1 2)]
1 2 3 4 5 6
4 5 6 7 8 9
Indexing with the nested list does not effectively use the Cartesian outer product of the two indexes (lists).
Here’s another example that demonstrates the issue and potential “feature” in indexing:
q)x[1 2;2 3]
6
9
q)x[1 2;3 4]
q)x[2 3;3 4]
'length
Hi Erik,
I think I got what you mean. Please see the answers below: