xor operator?
Hans Nowak
ivnowa at hvision.nl
Fri Jan 26 10:25:31 EST 2001
Nicola Musatti wrote:
> > Very few languages have a boolean xor operation. I don't know any off the
> > top of my head, but if I'd have to make a guess, I'd say that INTERCAL was
> > the only language I'm famialiar with, with a boolean XOR operation :)
Pascal does. I'm not sure about standard Pascal (if there is such a
thing), but Turbo Pascal did, and Delphi does today, too.
> > The simple reason is 'it isn't shortcuttable'. That is, with 'and' and 'or',
> > whether or not to evaluate the second argument is based on the outcome of
> > the first. xor requires you to always evaluate both.
I see the difference, but I don't understand why that is a problem,
though.
> In the specific Python
> > sense, the return value of the boolean xor operation would also be vague.
Simply 0 or 1 would be a possibility, but that is not what Python's
'and' and 'or' do. So maybe, if it evaluates to true, it returns the
'true' element; otherwise it returns 0 (like 'and' and 'or' do).
> I'd say that a more plausible reason is that for boolean values 'xor' is
> equivalent to '!='.
Sounds reasonable to me. Still, for the sake of orthagonality, I would
expect it as the boolean counterpart to the binary xor (^). :) Then
again, Guido is not likely to add any new keywords to the language...
--Hans Nowak
--Info Vision Europe BV
More information about the Python-list
mailing list