www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ==, is

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
quick question: are the following rewrites always valid:

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

?
Nov 15 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Nov 15 2010
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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
Nov 15 2010
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Nov 15 2010
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Nov 15 2010
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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
Nov 15 2010
next sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Nov 15 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Nov 15 2010