64-bit bools were a mistake, tbh. Oh well, at least we tried.
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!
On 2021-02-23 5:49 a.m., Steven D'Aprano wrote:
On Mon, Feb 22, 2021 at 10:11:14PM -0300, Soni L. wrote:
> Currently ~False is -1 and ~True is -2. Would be nicer if ~bool was the
> same as not bool.
That's your opinion. I disagree.
Bitwise-not is not the same thing as boolean-not, and they should not be
spelled the same, especially not when that would break the invariant
that if `a == b` then `~a == ~b`.
>>> 0 == False
True
>>> ~0 == ~False
True
If you want boolean-not, then use the boolean-not operator `not`.
> In particular, this is nice for xnor operator: a ^~ b. This currently
> works on ints, but not on bools
If it works on ints, of course it works on bools, because bools are
ints. You get identical results whether you use int (0, 1) or bools
(False, True) in every combination:
>>> def xnor(a, b):
... return a ^ ~b
...
>>> [xnor(a, b) for a in (0, 1) for b in (0, 1)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (0, 1) for b in (False, True)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (False, True) for b in (0, 1)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (False, True) for b in (False, True)]
[-1, -2, -2, -1]
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/KES7CSGDKZC2J6F5NSWZNLQH744BBLJR/
Code of Conduct: http://python.org/psf/codeofconduct/