in reply to Re: adding/subtracting calender dates
in thread adding/subtracting calender dates

Hmmm well it seemed to work like I wanted. Please let me know what you think it does. It would be great to know what it really does as to what I think it does. Thanks again... Fue
  • Comment on Re^2: adding/subtracting calender dates

Replies are listed 'Best First'.
xor =
by hubb0r (Pilgrim) on Jun 02, 2005 at 20:50 UTC
    FYI - xor is an "exclusive or". It has the following rules:
    (1 xor 1) == 0 (1 xor 0) == 1 (0 xor 1) == 1 (0 xor 0) == 0 (0 xor 1 xor 1) == 0 (0 xor 1 xor 0) == 1 etc etc
    Meaning that it will return true if and only if exactly 1 of the xor'd variables returns true.

      Close, but not quite. Try this for example:

      print "foo" if (1 xor 1 xor 1);

      prints foo, since

      (1 xor 1 xor 1) == ((1 xor 1) xor 1) == ( ( 0 ) xor 1 ) == 1

      In general terms, xor actually returns true if an odd number of true values exist in the set. In the cases where the set is of size two, this means exactly one truth. That doesn't generalize, though.

      addendum: In the OPs case, though, it worked because his alternatives were all mutually exclusive. However, since xor can't shortcircuit, it took a lot longer to work than a normal or.