Thread overview
==, is
Nov 15, 2010
Ellery Newcomer
Nov 15, 2010
Ellery Newcomer
Nov 15, 2010
Jonathan M Davis
Nov 15, 2010
Ellery Newcomer
Nov 15, 2010
Jonathan M Davis
November 15, 2010
quick question: are the following rewrites always valid:

e1 != e2     ->   !(e1 == e2)
e1 !is e2    ->   !(e1 is e2)
e1 !in e2    ->   !(e1 in e2)

?
November 15, 2010
On Mon, 15 Nov 2010 14:06:34 -0500, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> quick question: are the following rewrites always valid:
>
> e1 != e2     ->   !(e1 == e2)
> e1 !is e2    ->   !(e1 is e2)
> e1 !in e2    ->   !(e1 in e2)

I believe this is in fact what the compiler does (rewriting).

-Steve
November 15, 2010
parser definitely does it for !in, but it doesn't for the other ones, and I didn't want to go digging all over the place for it.

Also, spec says yes for !in, but is silent for the other ones

On 11/15/2010 01:08 PM, Steven Schveighoffer wrote:
> On Mon, 15 Nov 2010 14:06:34 -0500, Ellery Newcomer
> <ellery-newcomer@utulsa.edu> wrote:
>
>> quick question: are the following rewrites always valid:
>>
>> e1 != e2 -> !(e1 == e2)
>> e1 !is e2 -> !(e1 is e2)
>> e1 !in e2 -> !(e1 in e2)
>
> I believe this is in fact what the compiler does (rewriting).
>
> -Steve
November 15, 2010
On Mon, 15 Nov 2010 14:36:33 -0500, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> parser definitely does it for !in, but it doesn't for the other ones, and I didn't want to go digging all over the place for it.
>
> Also, spec says yes for !in, but is silent for the other ones

http://www.digitalmars.com/d/2.0/operatoroverloading.html#equals

As far as is, it doesn't explicitly say that rewriting is done, but, it does spell out that to do the opposite, use !is.  Maybe the spec should be updated to explicitly say x !is y is the same as !(x is y).

http://www.digitalmars.com/d/2.0/expression.html#IdentityExpression

>
> On 11/15/2010 01:08 PM, Steven Schveighoffer wrote:
>> On Mon, 15 Nov 2010 14:06:34 -0500, Ellery Newcomer
>> <ellery-newcomer@utulsa.edu> wrote:
>>
>>> quick question: are the following rewrites always valid:
>>>
>>> e1 != e2 -> !(e1 == e2)
>>> e1 !is e2 -> !(e1 is e2)
>>> e1 !in e2 -> !(e1 in e2)
>>
>> I believe this is in fact what the compiler does (rewriting).
>>
>> -Steve
November 15, 2010
On Monday 15 November 2010 11:47:11 Steven Schveighoffer wrote:
> On Mon, 15 Nov 2010 14:36:33 -0500, Ellery Newcomer
> 
> <ellery-newcomer@utulsa.edu> wrote:
> > parser definitely does it for !in, but it doesn't for the other ones, and I didn't want to go digging all over the place for it.
> > 
> > Also, spec says yes for !in, but is silent for the other ones
> 
> http://www.digitalmars.com/d/2.0/operatoroverloading.html#equals
> 
> As far as is, it doesn't explicitly say that rewriting is done, but, it does spell out that to do the opposite, use !is.  Maybe the spec should be updated to explicitly say x !is y is the same as !(x is y).

Honestly, I don't see how it could be otherwise. I would have just assumed that they were identical.

- Jonathan M Davis
November 15, 2010
a while ago, I assumed that

e1 += e2

gets rewritten as

e1 = e1 + e2

Yeah. It doesn't. It doesn't even behave the same wrt erroneously typed arguments

On 11/15/2010 02:35 PM, Jonathan M Davis wrote:
>> As far as is, it doesn't explicitly say that rewriting is done, but, it
>> does spell out that to do the opposite, use !is.  Maybe the spec should be
>> updated to explicitly say x !is y is the same as !(x is y).
>
> Honestly, I don't see how it could be otherwise. I would have just assumed that
> they were identical.
>
> - Jonathan M Davis
November 15, 2010
On Monday 15 November 2010 12:40:43 Ellery Newcomer wrote:
> a while ago, I assumed that
> 
> e1 += e2
> 
> gets rewritten as
> 
> e1 = e1 + e2
> 
> Yeah. It doesn't. It doesn't even behave the same wrt erroneously typed arguments

Well, that would potentially be two different set of operator overloads (+= vs = and/or +), so they definitely can't act the same, though I can see why you'd think so at first glance. None of the operators that you specificy have that problem. Still, it pays to be careful. It can be easy to make erroneous assumptions.

- Jonathan M Davis
November 15, 2010
On Mon, 15 Nov 2010 15:40:43 -0500, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:

> a while ago, I assumed that
>
> e1 += e2
>
> gets rewritten as
>
> e1 = e1 + e2
>
> Yeah. It doesn't. It doesn't even behave the same wrt erroneously typed arguments

I understand the care taken, but the spec gives reasons to believe otherwise:

There is opAdd and opAddAssign

There are opEquals and opIn, but no opNotEquals and opNotIn.

If you can override the operators independently, naturally you should not expect that one is rewritten, otherwise why have the independent operators?

Likewise, if there is no overload for the opposite, then it must be a rewriting function.

'is' is sorta different because you can't override it either way.

-Steve