missing 'xor' Boolean operator

Delaney, Timothy (Tim) tdelaney at avaya.com
Sun Jul 26 20:53:33 EDT 2009


Mark Dickinson wrote:

>> Since the 'and' and 'or' already return objects (and objects
>> evaluate to true or false), then 'xor' should behave likewise, IMO.
>> I expect that would be the case if it were ever added to the
>> language. 
> 
> I'm not so sure.  Did you ever wonder why the any() and all()
> functions introduced in 2.5 return a boolean rather than returning
> one of their arguments?  (I did, and I'm still not sure what the
> answer is.)

Consider the case of any() and all() operating on an empty iterable.
What type should they return?

It is impossible in the case of any() and all() to always return one of
the elements due to this edge case. Similarly, it is impossible in all
cases for a boolean xor to return one of the arguments - if both
arguments evaluate to a true (Something) value, xor must return a false
(Nothing) result.

Tim Delaney



More information about the Python-list mailing list