KDB+ 3.2 2015.01.20 Copyright (C) 1993-2015 Kx Systems
l32/ 2()core 1748MB jack ut 127.0.1.1 NONEXPIRE
q)0 in (0;0)
1b
q)0 in (0;1 2)
1b
q)0 in (1 2;0)
0b
why?
q)0 1 in (0;1 2)
10b
q)0 1 in (1 2;0)
0b
shouldn’t there be a list of two booleans here?
ta, jack.
Use the each adverb to search inside the sublists:
q)0 in’ (1 2;0)
01b
q)0 1 in’ (0;1 2)
11b
q)0 1 in’ (1 2;0)
00b
On Monday, 15 June 2015 10:46:08 UTC+1, effbiae wrote:
KDB+ 3.2 2015.01.20 Copyright (C) 1993-2015 Kx Systems
l32/ 2()core 1748MB jack ut 127.0.1.1 NONEXPIRE
q)0 in (0;0)
1b
q)0 in (0;1 2)
1b
q)0 in (1 2;0)
0b
why?
q)0 1 in (0;1 2)
10b
q)0 1 in (1 2;0)
0b
shouldn’t there be a list of two booleans here?
ta, jack.
untype the list, if what you are looking for is 10b. 0 is indeed in the list, so should return 1b.
q)0 1 in (::),(1 2;0)
10b
It looks like ‘in’ converts left element to atom or list based on first element of right hand side. Check following examples:
q) 0 in (2;enlist 0)
0b / first element of RHS (2) is an atom, left side 0 remains an atom and doesn’t matches with enlist 0
q) 0 in ( 1 2;enlist 0)
1b / first element of RHS(1 2) is a list, so LHS 0 gets converted to enlist 0
it is same as
q) (enlist 0) in ( 1 2;enlist 0)
1b
q) (enlist 0) in (2;enlist 0)
,0b / LHS (enlist 0) gets converted to 0.
q) (enlist 0) in (2 4;enlist 0)
,1b
in is rank sensitive, and rank is defined by first element recursively.
?, bin, except and dict look-ups work the same way.
Are you referring to function/operator rank or the rank of the operands? I don’t see rank (other than the built-in function) referenced in the Borror book’s index. Can you please post a link to some page or documentation that describes this? Coming from an APL background I’m having a bit of difficulty getting my head around the current behavior and would like to understand it. Thanks.
Tiago,
The Each adverb won’t always fix the underlying issue. Consider the following:
q)0 1 2 ? (((1; 2 3); 4 5); 6 7)
'type
When the left operand is a simple list find is supposed to be atomic (pervasive) on the right operand according to the Borror book–and I still don’t understand how rank is defined in Q. For some reason if the first depth 0 or 1 value (I’m not sure how to properly explain this in Q terms) is an atom (i.e. 1 in this case), the expression fails with a 'type error. I don’t believe each can be used to produce the expected result due to the variable depths of the items of the list.
If the first value (i.e. 2 is a simple list (i.e. 2 3 in this case), the expression works as expected:
q)0 1 2 ?(((2 3; 1);4 5);6 7)
2 3 1 3 3
3 3