Does Python need an 'xor' operator?

Grant Edwards grante at visi.com
Sun Apr 14 13:13:39 EDT 2002


In article <mailman.1018797388.28608.python-list at python.org>, jepler at unpythonic.net wrote:

> This follows (kinda) from the identity
>     a xor b == (a or b) and not (a and b)
> 
> I'm sure this is in keeping with the spirit of Python.  It doesn't
> short circuit, but it returns one of its arguments when possible,
> and returns the 'not' of one of its arguments in the fourth case.
> There's no short-circuit evaluation, but that's just too bad.

I wouldn't say it's "too bad" that there's no short-circuit
evaluation any more than it's just too bad that the addition
operator doesn't do short-circuit evaluation of it's operands.

The definition of the operation requires that both operands be
evaluated.  Arguing that xor shouldn't be implimented because
it doesn't do short-circuit evaluation is a non-sequitor.  If
that were a valid argument then we'd have to throw out most of
the existing binary operators.

-- 
Grant Edwards                   grante             Yow!  .. Should I get
                                  at               locked in the PRINCIPAL'S
                               visi.com            OFFICE today -- or have
                                                   a VASECTOMY??



More information about the Python-list mailing list