August 20, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:3D61F29C.7090600@users.sourceforge.net... > The utility is a whole other matter. I consider "a.exp (b)" superior to > "(a exp b)" because: > > a) It's explicit about who's doing what to whom. Operator precedence is a non-issue. > > b) It doesn't keep exp from being used in various contexts. > > c) It's the same number of characters. > > d) The (a exp b) syntax doesn't offer anything new. > > e) Making expressions look closer to mathematical drawings is an IDE issue, not a lingual responsibility, and they're facilitated in this by keeping things simple and as method-based as possible. I agree with your reasoning. I don't think (a exp b) offers enough additional utility to make it worthwhile. | |||
August 20, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Martin M. Pedersen | "Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:ajtnne$1a2r$1@digitaldaemon.com... > Hi, > > "Pavel Minayev" <evilone@omen.ru> wrote in message news:CFN374888137990278@news.digitalmars.com... > > Logical xor is operator != > > Not exactly, as 2!=1 yields true. != is only a logical xor if the operands are guaranteed to be either 0 or 1. So, instead use !a != !b. Still not inconvenient. The benefit from the logical operators && and || is their short-circuit behavior (sometimes only the left hand side need be evaluated). Except for that, there's scarcely any reason to have them. Considering this, why have a logical xor, since it's not short-circuit-able (both sides must always be evaluated)? It's similarly hard to justify the &&= and ||= operators. | |||
August 20, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Martin M. Pedersen | I actually do find myself wanting &&= and ||= quite a lot.
bool succeeded = true;
succeeded &&= TrySomething();
succeeded &&= TrySomethingElse();
if (!succeeded)
printf("Either TrySomething or TrySomethingElse failed\n");
Sean
"Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:ajtmff$18nu$1@digitaldaemon.com...
> Hi,
>
> "Walter" <walter@digitalmars.com> wrote in message news:ajpa1n$268h$1@digitaldaemon.com...
> > > > Hm... Maybe a^^b?
> > > It looks like a logical xor to me.
> > It's been proposed as a logical xor for C many times.
>
> I often wondered why it wasn't there, as it would make the set of
operators
> more consistent. It seems that I'm not the only one. The same could be
said
> about &&= and ||=. However, I can't say I have missed them much, and the
set
> of operators in D is already large enough. So consider this a comment, not
a
> proposal for D. Keep up the good work.
>
> Regards,
> Martin
| |||
August 20, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Richard Krehbiel | Hi, "Richard Krehbiel" <rich@kastle.com> wrote in message news:ajtqvv$1daq$1@digitaldaemon.com... > > Not exactly, as 2!=1 yields true. != is only a logical xor if the operands > > are guaranteed to be either 0 or 1. > So, instead use !a != !b. Still not inconvenient. Maybe not. But a bit inconsistent, I think. No big issue, though. > The benefit from the logical operators && and || is their short-circuit behavior (sometimes only the left hand side need be evaluated). Good point. > Considering this, why have > a logical xor, since it's not short-circuit-able (both sides must always be > evaluated)? It's similarly hard to justify the &&= and ||= operators. I would expect them to short-circuit too. Regards, Martin M. Pedersen | |||
August 20, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Richard Krehbiel | On Tue, 20 Aug 2002 12:38:35 -0400 "Richard Krehbiel" <rich@kastle.com> wrote:
> evaluated)? It's similarly hard to justify the &&= and ||= operators.
This can be used to break long boolean expression into several short ones, like it is sometimes done with arithmetic.
| |||
August 21, 2002 Re: Reverse Operator Overloading | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Martin M. Pedersen | "Martin M. Pedersen" <mmp@www.moeller-pedersen.dk> wrote in message news:ajtv3s$1i83$1@digitaldaemon.com... > Hi, > > "Richard Krehbiel" <rich@kastle.com> wrote in message news:ajtqvv$1daq$1@digitaldaemon.com... > > The benefit from the logical operators && and || is their short-circuit behavior (sometimes only the left hand side need be evaluated). > > Good point. > > > Considering this, why have > > a logical xor, since it's not short-circuit-able (both sides must always > be > > evaluated)? It's similarly hard to justify the &&= and ||= operators. > > I would expect them to short-circuit too. You know, I didn't think about that hard enough. &&= and ||= could indeed short-circuit, they could be defined not to evaluate the left side if the right side is zero/non-zero, which can be a big win if it's something like "DBlookup()->array[VMthrasher()] ||= var;". But of course, today you'd code it as "if(var) DBlookup()->array[VMthrasher()] |= 1;". Still not such a big deal, I think. -- Richard Krehbiel, Arlington, VA, USA rich@kastle.com (work) or krehbiel3@comcast.net (personal) | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply