[Python-ideas] Discussion about a 'xor' keyword?
Emanuel Barry
vgr255 at live.ca
Sun Oct 18 03:54:54 CEST 2015
> Date: Sat, 17 Oct 2015 17:50:36 -0700
> Subject: Re: [Python-ideas] Discussion about a 'xor' keyword?
> From: pyideas at rebertia.com
> To: vgr255 at live.ca
> CC: python-ideas at python.org
>
>
> This 2009 discussion was more vigorous:
> https://mail.python.org/pipermail/python-list/2009-July/543956.html
Having a look right now. Looks interesting.
> I would be interested to hear what your concrete use cases for xor are.
I have a few from the top of my head (not backed by code right now, will post some when I feel like digging into it).
For an IRC game bot I work on, we have a special message if someone has two targets available, but a different one if they have only one - although it's the same message, and we made a complicated conditional just for that. A xor keyword would have saved us that trouble.
In a library I dug in some time ago (I didn't make it), an exception was raised if two parameters had a True (or False) value - one of them had to be True. I (probably naively) think that some more libraries do that.
My friend in college is learning programming, and for his projects he says he really wants to see a 'xor' keyword in, as he has to do some mangling to get what he wants. I'm unaware what his work consists of, however.
------------------
'xor' would by no means be as common as any existing operator, but I believe it is a good addition to consider. Another upside is that keywords only evaluate the value once, so chaining two wouldn't re-evaluate the value (in the case of a function/property).
>From that 2009 discussion, most of the rejections focused on "You can coerce to bool before then perform the xor operations", but I'm considering not coercing to bool here, so I think it is different enough to the other discussion to (at least in my opinion) bring it up one more time. If I wanted boolean coercion, I'd just do it myself.
Also, the fact that other people have considered the idea before makes me think that it's not as rare a case as some may think.
-Emanuel Barry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151017/337f0d3e/attachment.html>
More information about the Python-ideas
mailing list