Skip to content

? Vector Conditional

Replace selected items of one list with corresponding items of another

?[x;y;z]

Where

  • x is a boolean vector
  • y and z are lists of the same type
  • x, y, and z conform

returns a new list by replacing elements of y with the elements of z when x is false.

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 atomic, they are repeated.

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

Since V2.7 2010.10.07 ?[x;y;z] works for atoms too.

Vector Conditional can be used in qSQL queries, which do not support Cond.

For multiple cases – more than just true/false – see Controlling evaluation.


? Query, Cond, if
Controlling evaluation
Q for Mortals §10.1.3 Vector Conditional Evaluation