cancel
Showing results for 
Search instead for 
Did you mean: 

AND and OR in conditionals?

xapwing
New Contributor
Tried to find if AND and OR are supported in conditionals in Q.

I just tried to type in:
   and
and get response:
   &
also tried:
   or
and got response: 
   |

However when I enter:
   1 | 2
i get response:
   2

So it seems to return the maximum of the two numbers
Also & seems to retrun the minimum.

What is the meaning / background?
4 REPLIES 4

WooiKent_Lee
New Contributor
It makes sense to me. OR requires any booleans to be true to pass, so taking the max of the booleans is the same logic.

q)0b|1b
1b
q)max 01b
1b

AND requires all booleans to be true to pass, so taking the min of booleans is also the same logic.

q)0b&1b
0b
q)min 01b
0b

rahul_asati04
Contributor
It is mentioned on wiki page that '|' behaves as max and '&' as min.

http://code.kx.com/wiki/Reference/Bar
http://code.kx.com/wiki/Reference/Ampersand

Thx. Had some difficulty to find the right docs and thus missed those implications 😉

2015-07-13 17:26 GMT+02:00 RAHUL ASATI <rahul.asati04@gmail.com>:
It is mentioned on wiki page that '|' behaves as max and '&' as min.

http://code.kx.com/wiki/Reference/Bar
http://code.kx.com/wiki/Reference/Ampersand

erik_friis
New Contributor
The background is that the boolean cases are essentially the degenerate cases (as demonstrated above)  so recognizing that the domain of & and | have been elegantly extended to all integers.  This behavior started in various dialects of APL, then J & K, and now Q.  It's a good extension but it's not new.