digitalmars.D.learn - ==, is
- Ellery Newcomer (5/5) Nov 15 2010 quick question: are the following rewrites always valid:
- Steven Schveighoffer (4/8) Nov 15 2010 I believe this is in fact what the compiler does (rewriting).
- Ellery Newcomer (4/13) Nov 15 2010 parser definitely does it for !in, but it doesn't for the other ones,
- Steven Schveighoffer (7/23) Nov 15 2010 http://www.digitalmars.com/d/2.0/operatoroverloading.html#equals
- Jonathan M Davis (4/17) Nov 15 2010 Honestly, I don't see how it could be otherwise. I would have just assum...
- Ellery Newcomer (7/13) Nov 15 2010 a while ago, I assumed that
- Jonathan M Davis (7/17) Nov 15 2010 Well, that would potentially be two different set of operator overloads ...
- Steven Schveighoffer (12/18) Nov 15 2010 I understand the care taken, but the spec gives reasons to believe
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
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
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
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 oneshttp://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#IdentityExpressionOn 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
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:Honestly, I don't see how it could be otherwise. I would have just assumed that they were identical. - Jonathan M Davisparser 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 oneshttp://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).
Nov 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
Nov 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 argumentsWell, 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
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 argumentsI 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