Topic: Why must logical XOR behave like && || ?
Author: ark@acm.org ("Andrew Koenig")
Date: Tue, 6 Jul 2004 18:36:31 +0000 (UTC) Raw View
""Stephen Howe"" <sjhowe@dial.pipex.com> wrote in message
news:40e9e349$0$26959$cc9e4d1f@news.dial.pipex.com...
> Anytime I find I have something like
>
> >>>>>>>>>>>>>>>>>>>>
> int x, y;
>
> :
> // x, y are set
> :
> if (x > 0 != y > 0)
> {
> // do something
> }
> >>>>>>>>>>>>>>>>>>>>
>
> I would far rather write
>
> >>>>>>>>>>>>>>>>>>>>
> if (x > 0 ^^ y > 0)
> {
> // do something
> }
> >>>>>>>>>>>>>>>>>>>>
I must confess that I've never had the need to write a condition of this
form--but if I did, I wouldn't see anything wrong with writing
if (x > 0 ^ y > 0) { /* do something */ }
> or worse
>
> >>>>>>>>>>>>>>>>>>>>
> bool b1, b2, b3, b4;
> :
> // b1, b2, b3, b4 set
> :
> if (b1 != b2 != b3 != b4)
> // something
> >>>>>>>>>>>>>>>>>>>>
>
> rather than
>
> >>>>>>>>>>>>>>>>>>>>
> if (b1 ^^ b2 ^^ b3 ^^b4)
> // something
> >>>>>>>>>>>>>>>>>>>>
>
> which does explicitly convey that logical XOR is being tested for.
As would
if (b1 ^ b2 ^ b3 ^ b4)
> Further != does not have the right precedence, it is higher than &, | and
^
> operators whereas I would expect ^^ to be between && and || just like ^ is
> between & and |.
The question is whether the once or twice a year you think you need it is a
sufficient argument for putting it into C++, noting that in both of the
examples you gave, the already existing ^ operator would work just fine.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: sjhowe@dial.pipex.com ("Stephen Howe")
Date: Mon, 5 Jul 2004 16:17:11 +0000 (UTC) Raw View
> > > Is there really such a pressing need for this?
>
> > I guess not. But likewise, there is no need for || as it can be written
in
> > terms of && and !
> > So we should scrap one of || or && by this logic.
>
> Nonsense. The only conclusion you can reasonably draw is that if C did
not
> already have both && and ||, it might not make sense to add the missing
one
> of those to C++.
My point was tongue-in-cheek.
C does not have a strict minimal set of operators and therefore "pressing
need" is an absurd position for the addtion of logical XOR to C and C++.
Stephen Howe
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: sjhowe@dial.pipex.com ("Stephen Howe")
Date: Tue, 6 Jul 2004 02:47:12 +0000 (UTC) Raw View
> Many users? I must confess that I have never had occasion to write a
> program that would have used ^^ if it were available. So can you give us
a
> few examples of where this ^^ operator would be useful?
Anytime I find I have something like
>>>>>>>>>>>>>>>>>>>>
int x, y;
:
// x, y are set
:
if (x > 0 != y > 0)
{
// do something
}
>>>>>>>>>>>>>>>>>>>>
I would far rather write
>>>>>>>>>>>>>>>>>>>>
if (x > 0 ^^ y > 0)
{
// do something
}
>>>>>>>>>>>>>>>>>>>>
or worse
>>>>>>>>>>>>>>>>>>>>
bool b1, b2, b3, b4;
:
// b1, b2, b3, b4 set
:
if (b1 != b2 != b3 != b4)
// something
>>>>>>>>>>>>>>>>>>>>
rather than
>>>>>>>>>>>>>>>>>>>>
if (b1 ^^ b2 ^^ b3 ^^b4)
// something
>>>>>>>>>>>>>>>>>>>>
which does explicitly convey that logical XOR is being tested for. With the
other expression, I would be wondering if the programmer's intentions really
were to do logical XOR (particularly if he/she has left).
I freely admit, I don't often use the equivalent of logical XOR in code, but
when I need it, I prefer if it was present rather than have to make do with
!=. I must have used it about once a year in terms of coding (and "goto"
about once every two years).
Further != does not have the right precedence, it is higher than &, | and ^
operators whereas I would expect ^^ to be between && and || just like ^ is
between & and |.
Stephen Howe
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Sun, 13 Jun 2004 20:36:53 +0000 (UTC) Raw View
stephenPOINThoweATtns-globalPOINTcom@eu.uu.net ("Stephen Howe") writes:
>> Is there really such a pressing need for this?
>
> I guess not. But likewise, there is no need for || as it can be written in
> terms of && and !
> So we should scrap one of || or && by this logic.
Actually, only NAND is necessary. C++ should add a NAND logic
operator and scrap the rest. :-)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: anti_spam_email2003@yahoo.com (Me)
Date: Fri, 11 Jun 2004 16:43:19 +0000 (UTC) Raw View
> Here is a nice summary of pros and cons for the logical XOR operator:
> http://groups.google.com/groups?selm=7f2735a5.0210281756.300f190b%40posting.google.com
Another con is that if you added it:
and means &&, bitand means &, but xor already means ^
C/C++ doesn't need another embarrassment like this so it's best not to
resurrect this thread ever again.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stephenPOINThoweATtns-globalPOINTcom@eu.uu.net ("Stephen Howe")
Date: Tue, 8 Jun 2004 22:05:51 +0000 (UTC) Raw View
> Is there really such a pressing need for this?
I guess not. But likewise, there is no need for || as it can be written in
terms of && and !
So we should scrap one of || or && by this logic.
Stephen Howe
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ark@acm.org ("Andrew Koenig")
Date: Wed, 9 Jun 2004 02:41:56 +0000 (UTC) Raw View
""Stephen Howe"" <stephenPOINThoweATtns-globalPOINTcom@eu.uu.net> wrote in
message news:40c6334a$0$20513$ed9e5944@reading.news.pipex.net...
> > Is there really such a pressing need for this?
> I guess not. But likewise, there is no need for || as it can be written in
> terms of && and !
> So we should scrap one of || or && by this logic.
Nonsense. The only conclusion you can reasonably draw is that if C did not
already have both && and ||, it might not make sense to add the missing one
of those to C++.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Fri, 4 Jun 2004 16:06:26 +0000 (UTC) Raw View
kprateek88@yahoo.com (Prateek R Karandikar) writes:
> Recently I had asked why there is no logical XOR operator. The reply I
> got was that "If there is a logical XOR operator, it must behave like
> the AND and OR operators, which is not possible, so we don't have it
> at all!" Why must the hypothetical XOR operator have to behave like
> AND and OR?
[snip]
This explanation arises becuase people assume that a logical XOR
operator was considered and rejected. I know of no evidence that
it was considred for either C or C++. Some things just aren't
thought of.
IMO, it is a rationalization.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Fri, 4 Jun 2004 16:08:59 +0000 (UTC) Raw View
In article <c9o214$ggr$1@news.Stanford.EDU>, Seungbeom Kim
<musiphil@bawi.org> writes
>Prateek R Karandikar wrote:
>> Recently I had asked why there is no logical XOR operator.
>
>Here is a nice summary of pros and cons for the logical XOR operator:
>http://groups.google.com/groups?selm=7f2735a5.0210281756.300f190b%40post
>ing.google.com
Thanks. However I think discussion of the issue should now be marked as
off topic and the summary placed in the FAQ. If anyone wants either ^^
or => they are free to write up a proposal for WG21. However, IMO,
unless they can find a sponsor for such a paper who actually attends
WG21 meetings they would be wasting their time. We have lots of real
work to do with serious impact on the language without spending the
hours that would be necessary to add these operators to the WP.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: austern@well.com (Matt Austern)
Date: Wed, 2 Jun 2004 17:43:42 +0000 (UTC) Raw View
kprateek88@yahoo.com (Prateek R Karandikar) writes:
> Recently I had asked why there is no logical XOR operator. The reply I
> got was that "If there is a logical XOR operator, it must behave like
> the AND and OR operators, which is not possible, so we don't have it
> at all!"
That's not precisely the argument. A more precise way of putting it
is: logical xor is unnecessary. We want to make a distinction between
& and &&, and between | and ||, because they mean different things.
If 'x' and 'y' are expressions of type bool, then 'x & y' means
evaluate x, evaluate y, and then return true iff x and y are both
true. 'x && y' means something different: evaluate 'x', then return
either 'false' or the value of 'y', depending on what you get from
evaluating 'x'. We need two operators because we've got two
different operations.
In the case of logical xor, there's no difference. If 'x' and 'y' are
two expressions of type bool, then we've already got two perfectly
good ways of getting a result that's true iff one and only one of the
arguments is true: either 'x != y' or 'x ^ y'. Why invent a third way
of writing the same thing?
(And if 'x' and 'y' are expressions that *don't* have type bool?
Well, then don't use them in boolean expressions! Or if what you
really mean is that you want the logical xor of what you'd get by
converting 'x' and 'y' to bool, then it's easy enough to just say so.)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: allan_w@my-dejanews.com (Allan W)
Date: Wed, 2 Jun 2004 19:12:15 +0000 (UTC) Raw View
kprateek88@yahoo.com (Prateek R Karandikar) wrote
> Recently I had asked why there is no logical XOR operator.
You can do logical XOR despite the lack of a built-in operator.
- If the arguments are already bool, use != as the XOR operator.
- Otherwise, use ! on each operator, then use !=.
inline bool XOR(bool a, bool b) { return a != b; }
..or just...
if ((!a) != (!b)) //if (a ^^ b)
I think you'll find that these are just as efficient as operator^^()
could have been, if such a thing existed.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Barry Margolin <barmar@alum.mit.edu>
Date: Wed, 2 Jun 2004 14:19:46 CST Raw View
In article <m27juqzi2j.fsf@Matt-Austerns-Computer.local>,
austern@well.com (Matt Austern) wrote:
> (And if 'x' and 'y' are expressions that *don't* have type bool?
> Well, then don't use them in boolean expressions! Or if what you
> really mean is that you want the logical xor of what you'd get by
> converting 'x' and 'y' to bool, then it's easy enough to just say so.)
I think that may be the issue. && and || have *two* special features:
they perform shortcut evaluation and they also treat their arguments as
booleans (even before the C language had a distinct boolean type).
Although the desired ^^ operator cannot sensibly provide shortcut
evaluation, many users would apparently still like it for the automatic
booleanization, so they don't have to write the explicit casts.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ark@acm.org ("Andrew Koenig")
Date: Wed, 2 Jun 2004 19:37:01 +0000 (UTC) Raw View
"Barry Margolin" <barmar@alum.mit.edu> wrote in message
news:barmar-EA3834.15172702062004@comcast.dca.giganews.com...
> I think that may be the issue. && and || have *two* special features:
> they perform shortcut evaluation and they also treat their arguments as
> booleans (even before the C language had a distinct boolean type).
> Although the desired ^^ operator cannot sensibly provide shortcut
> evaluation, many users would apparently still like it for the automatic
> booleanization, so they don't have to write the explicit casts.
Many users? I must confess that I have never had occasion to write a
program that would have used ^^ if it were available. So can you give us a
few examples of where this ^^ operator would be useful?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ahp6@email.byu.edu ("Adam H. Peterson")
Date: Wed, 2 Jun 2004 19:38:05 +0000 (UTC) Raw View
> If 'x' and 'y' are expressions of type bool, then 'x & y' means
> evaluate x, evaluate y, and then return true iff x and y are both
> true.
More like "return true if x and y have at least one true bit in common."
0x1 & 0x2 returns 0 (false)
0x1 && 0x2 returns true
> 'x && y' means something different: evaluate 'x', then return
> either 'false' or the value of 'y', depending on what you get from
> evaluating 'x'.
More like the value of y coerced into a bool. (This isn't Perl, here ;) .)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "P.J. Plauger" <pjp@dinkumware.com>
Date: Wed, 2 Jun 2004 15:28:56 CST Raw View
""Andrew Koenig"" <ark@acm.org> wrote in message
news:GUpvc.23055$_k3.572899@bgtnsc05-news.ops.worldnet.att.net...
> "Barry Margolin" <barmar@alum.mit.edu> wrote in message
> news:barmar-EA3834.15172702062004@comcast.dca.giganews.com...
>
> > I think that may be the issue. && and || have *two* special features:
> > they perform shortcut evaluation and they also treat their arguments as
> > booleans (even before the C language had a distinct boolean type).
> > Although the desired ^^ operator cannot sensibly provide shortcut
> > evaluation, many users would apparently still like it for the automatic
> > booleanization, so they don't have to write the explicit casts.
>
> Many users? I must confess that I have never had occasion to write a
> program that would have used ^^ if it were available. So can you give us
a
> few examples of where this ^^ operator would be useful?
To be fair, I can recall nearly half a dozen times over the last third
of a century when I felt moved to write such a thing. Of course I've
always found a suitable way to express it in a line or two of code,
so I've never felt that was strong enough evidence to add yet another
operator to the language.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: barmar@alum.mit.edu (Barry Margolin)
Date: Thu, 3 Jun 2004 17:26:13 +0000 (UTC) Raw View
In article <GUpvc.23055$_k3.572899@bgtnsc05-news.ops.worldnet.att.net>,
ark@acm.org ("Andrew Koenig") wrote:
> "Barry Margolin" <barmar@alum.mit.edu> wrote in message
> news:barmar-EA3834.15172702062004@comcast.dca.giganews.com...
>
> > I think that may be the issue. && and || have *two* special features:
> > they perform shortcut evaluation and they also treat their arguments as
> > booleans (even before the C language had a distinct boolean type).
> > Although the desired ^^ operator cannot sensibly provide shortcut
> > evaluation, many users would apparently still like it for the automatic
> > booleanization, so they don't have to write the explicit casts.
>
> Many users? I must confess that I have never had occasion to write a
> program that would have used ^^ if it were available. So can you give us a
> few examples of where this ^^ operator would be useful?
Since threads like this one pop up very frequently, there seem to be
many users who think it would be useful.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: austern@well.com (Matt Austern)
Date: Thu, 3 Jun 2004 17:27:34 +0000 (UTC) Raw View
ahp6@email.byu.edu ("Adam H. Peterson") writes:
> > If 'x' and 'y' are expressions of type bool, then 'x & y' means
> > evaluate x, evaluate y, and then return true iff x and y are both
> > true.
>
> More like "return true if x and y have at least one true bit in common."
>
> 0x1 & 0x2 returns 0 (false)
> 0x1 && 0x2 returns true
That's why I specified "If 'x' and 'y' are expressions of type
bool". 0x1 and 0x2 are values of type int, not of type bool.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (Seungbeom Kim)
Date: Thu, 3 Jun 2004 17:28:07 +0000 (UTC) Raw View
Andrew Koenig wrote:
>
> Many users? I must confess that I have never had occasion to write a
> program that would have used ^^ if it were available. So can you give us a
> few examples of where this ^^ operator would be useful?
I'm not particularly advocating the new operator, but
to be fair I'd like to mention that the way we think
depends upon the way the language that we have is.
Who knows whether you would have loved it if you had
had it from the beginning? :)
--
Seungbeom Kim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nagle@animats.com (John Nagle)
Date: Thu, 3 Jun 2004 17:29:10 +0000 (UTC) Raw View
P.J. Plauger wrote:
> ""Andrew Koenig"" <ark@acm.org> wrote in message
..
If we're going to have XOR, we might have
implication as well. Implication even shortcuts.
Of course you can use "<" for implication, but
readability suffers. Something to think about if
design by contract ever goes anywhere in C++.
John Nagle
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ark@acm.org ("Andrew Koenig")
Date: Thu, 3 Jun 2004 18:35:37 +0000 (UTC) Raw View
"Barry Margolin" <barmar@alum.mit.edu> wrote in message
news:barmar-78B7FB.23000602062004@comcast.dca.giganews.com...
> > Many users? I must confess that I have never had occasion to write a
> > program that would have used ^^ if it were available. So can you give
us a
> > few examples of where this ^^ operator would be useful?
> Since threads like this one pop up very frequently, there seem to be
> many users who think it would be useful.
Indeed. But that doesn't answer my question. I don't want to know whether
people think it is useful--I want to see actual examples of contexts in
which it would be useful. In my experience, people want all kinds of things
that they wouldn't actually use if they had them.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (Seungbeom Kim)
Date: Thu, 3 Jun 2004 20:45:33 +0000 (UTC) Raw View
Prateek R Karandikar wrote:
> Recently I had asked why there is no logical XOR operator.
Here is a nice summary of pros and cons for the logical XOR operator:
http://groups.google.com/groups?selm=7f2735a5.0210281756.300f190b%40posting.google.com
--
Seungbeom Kim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (Seungbeom Kim)
Date: Thu, 3 Jun 2004 20:45:56 +0000 (UTC) Raw View
John Nagle wrote:
> If we're going to have XOR, we might have
> implication as well. Implication even shortcuts.
I agree. Implication may be much more useful than XOR,
so it would be good to have implication even without having XOR.
I see a good use for implication in asserts where you want to
check some condition only when another condition is met:
assert(initialized => in_valid_range(x))
is a lot more intuitive than
assert(!initialized || in_valid_range(x))
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (Seungbeom Kim)
Date: Thu, 3 Jun 2004 21:30:43 +0000 (UTC) Raw View
Oops, my posting got truncated after a dot by itself in a line! :(
Let me continue:
John Nagle wrote:
> Of course you can use "<" for implication, but
> readability suffers. Something to think about if
> design by contract ever goes anywhere in C++.
In <http://groups.google.com/groups?selm=3DB2A18C.90D8B46D%40bawi.org>,
I had proposed "=>" for implication, named after the standard
mathematical notation. Does it cause any problem? I doubt it.
--
Seungbeom Kim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Tue, 1 Jun 2004 23:46:28 +0000 (UTC) Raw View
Recently I had asked why there is no logical XOR operator. The reply I
got was that "If there is a logical XOR operator, it must behave like
the AND and OR operators, which is not possible, so we don't have it
at all!" Why must the hypothetical XOR operator have to behave like
AND and OR? IMHO, This is like arguing:
" For integral x and y ( y!=0), not considering overflows, x+y, x-y,
x*y are exact, but x/y might be truncated; x+0, x-0, x*0 are
well-defined, but x/0 is not, so lets not have the / operation at
all.", which is clearly ridiculous.
The fact that the result of the AND and OR operations can be
determined without evaluating one argument if the other is false and
true respectively, but not so for XOR, is an intrinsic property of
these operations and the language cannot do anything about that. Also,
consider the statement (assuming a sequence point at the logical XOR
operator ^^):
"The &&, ||, ^^ operations evalute the 1st operand first, and then
evaluate the 2nd operand iff the result cannot be determined just
after the 1st evaluation."
The fact that the iff condition always holds for ^^ does not
invalidate the statement.
This way, assuming the existence of a not-so-necessary sequence point
at ^^, the above statement treats &&, ||, and ^^ similarly.
Besides, (assuming consistent declarations) f(++i,++i) is undefined,
but f((++i,++i)) is defined. If such similar looking constructs using
the same symbols can have such radically different semantics, then why
not &&,||,^^ ?
One might say that the symmetery between the operators might lead a
person to believe that (just like &&, ||) ^^ doesn't evaluate its 2nd
operand at times, thus confusing him/her. However this is impossible
and it means that the person does not know what the XOR operation is,
and if a programmer is ignorant about the operations he/she is using,
the language cannot do anything about that.
Hoping to see ^^ soon,
Prateek
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gi2nospam@mariani.ws (Gianni Mariani)
Date: Wed, 2 Jun 2004 15:10:29 +0000 (UTC) Raw View
Prateek R Karandikar wrote:
> Recently I had asked why there is no logical XOR operator. The reply I
> got was that "If there is a logical XOR operator, it must behave like
> the AND and OR operators, which is not possible, so we don't have it
> at all!" Why must the hypothetical XOR operator have to behave like
> AND and OR? IMHO, This is like arguing:
>
> " For integral x and y ( y!=0), not considering overflows, x+y, x-y,
> x*y are exact, but x/y might be truncated; x+0, x-0, x*0 are
> well-defined, but x/0 is not, so lets not have the / operation at
> all.", which is clearly ridiculous.
I thought logical xor would be the same as
bool a,b;
...
a != b
... ok, sometimes you need to cast
static_cast<bool>(a) != static_cast<bool>(b)
... or your compiler may be smart enough to opimize this
(!a) != (!b)
Hence I don't see any real need to add a new operator.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@comAcast.net (Victor Bazarov)
Date: Wed, 2 Jun 2004 15:11:22 +0000 (UTC) Raw View
Prateek R Karandikar wrote:
> Recently I had asked why there is no logical XOR operator.
> [...]
> Hoping to see ^^ soon,
Is there really such a pressing need for this? Couldn't you just
use != ?
bool(expression1) != bool(expression2)
should give you precisely the result of
expression1 ^^ expression2
, no? I mean, since you don't care much about the sequence point...
Victor
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: pjp@dinkumware.com ("P.J. Plauger")
Date: Wed, 2 Jun 2004 15:10:58 +0000 (UTC) Raw View
"Prateek R Karandikar" <kprateek88@yahoo.com> wrote in message
news:607f883e.0406011437.3eaa8f51@posting.google.com...
> Recently I had asked why there is no logical XOR operator. The reply I
> got was that "If there is a logical XOR operator, it must behave like
> the AND and OR operators, which is not possible, so we don't have it
> at all!" Why must the hypothetical XOR operator have to behave like
> AND and OR? IMHO, This is like arguing:
> .....
> [straw men omitted]
> .....
> Hoping to see ^^ soon,
Then come to a meeting or three and argue your case.
-- Ritchie omitted it a third of a century ago, and for good reason.
-- It comes up about once a year, and usually disappears within a
minute after an "Oh, yeah, never mind."
-- You can use the current ^ to get the same effect.
But if you feel strongly enough about it, put in some effort.
Hoping to see you soon,
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]