On 2021-02-23 7:10 p.m., Steven D'Aprano wrote:
On Tue, Feb 23, 2021 at 01:57:08PM -0300, Soni L. wrote:
What about getting the parser to recognize ^~ as an XNOR operator and have __xnor__ on bools actually do xnor on bools? Make xnor a real operator by fusing two operators together!
Let's not break existing code for the sake of an operator that hardly anyone ever uses.
There are exactly 2**4 = 16 boolean operators of two variables. Python only supports two: `and` and `or`. Plus a single unary operator `not` (out of four possible unary operators). What makes xnor so special that you want it to be an operator?
Do you have any use-cases for an xnor operator? What do you use it for?
These are not rhetorical questions. If you want to push this proposal forward, you need to start with actual concrete use-cases, not "it would be nice ..." and "how about ...".
Why can't you write a function to do what you want?
It's because someone was doing a comparison of a bool to the result of a comparison, a la (x == y) == z, and that looks kinda weird (especially because x == y == z has a completely different meaning). ^ works as a replacement for != but for == the only option is to either use "thing ^ (not foo)" or "not (thing ^ foo)". It's not that it's special - we "technically" already have it, if you abuse another language feature - it'd just make some code easier to understand.