? Vector Conditional¶
Replace selected items of one list with corresponding items of another
?[x;y;z]
Where
xis a boolean atom or vectoryandzare atoms or lists of the same typex,y, andzconform
returns
yifxis a true atom, orzifxis a false atom- a list that takes the items of
ywherexis true and the items ofzwherexis false, ifxis a list
All three arguments are evaluated.
q)?[11001b;1 2 3 4 5;10 20 30 40 50]
1 2 30 40 5
If x, y, or z are atoms, they are repeated. Since V2.7 2010.10.07 ?[x;y;z] works for atoms too.
q)?[11001b;1;10 20 30 40 50]
1 1 30 40 1
q)?[11001b;1 2 3 4 5;99]
1 2 99 99 5
q)?[0b;1;2]
2
x must be boolean. Other types signal a 'type error.
q)?[1 0 1;1 2 3;4 5 6]
'type
[0] ?[1 0 1;1 2 3;4 5 6]
^
You can use Vector Conditional in qSQL queries, which do not support Cond.
For more than two cases, see the Case iterator.
Q for Mortals §10.1.3 Vector Conditional Evaluation