this as lvalue?

2010-09-03 Thread JMRyan
I wouldn't have thought of "this" representing an lvalue. However, the following absurdity compiles and executes flawlessly. Just don't uncomment the assignment to y.i! class Yikes { int i; this() { this = null; } } void main() { auto y = new Yikes(); // y.i = 0; } Is this a

Re: this as lvalue?

2010-09-03 Thread bearophile
JMRyan: > Is this a bug in the compiler (v.2.047)? Am I missing something in > thinking it shouldn't be? I think it's not a bug. It's not a common need, but a method may way want to swap this with another. In Phobos this is done on a struct, see: http://www.dsource.org/projects/phobos/browser/t

Re: this as lvalue?

2010-09-03 Thread Jonathan M Davis
On Friday 03 September 2010 13:22:51 JMRyan wrote: > I wouldn't have thought of "this" representing an lvalue. However, the > following absurdity compiles and executes flawlessly. Just don't > uncomment the assignment to y.i! > > class Yikes > { > int i; > this() { this = null; } > } >

Re: this as lvalue?

2010-09-03 Thread Andrei Alexandrescu
On 9/3/10 16:03 CDT, bearophile wrote: JMRyan: Is this a bug in the compiler (v.2.047)? Am I missing something in thinking it shouldn't be? I think it's not a bug. It's not a common need, but a method may way want to swap this with another. In Phobos this is done on a struct, see: http://www

Re: this as lvalue?

2010-09-03 Thread Jonathan M Davis
On Friday 03 September 2010 14:22:46 Andrei Alexandrescu wrote: > On 9/3/10 16:03 CDT, bearophile wrote: > > JMRyan: > >> Is this a bug in the compiler (v.2.047)? Am I missing something in > >> thinking it shouldn't be? > > > > I think it's not a bug. It's not a common need, but a method may way

Re: this as lvalue?

2010-09-03 Thread Andrei Alexandrescu
On 9/3/10 16:33 CDT, Jonathan M Davis wrote: Still, I don't know how you could make it a true rvalue. It's very simple - make "this" the result of a hypothetical function call. Andrei

Re: this as lvalue?

2010-09-03 Thread Jonathan M Davis
On Friday 03 September 2010 14:38:27 Andrei Alexandrescu wrote: > On 9/3/10 16:33 CDT, Jonathan M Davis wrote: > > Still, I don't know how you could make it a true rvalue. > > It's very simple - make "this" the result of a hypothetical function call. > > Andrei Ah, that would do it. Though you w

Re: this as lvalue?

2010-09-03 Thread bearophile
Andrei Alexandrescu: > For classes this must be an rvalue. OK. Why? Bye, bearophile

Re: this as lvalue?

2010-09-03 Thread Andrei Alexandrescu
On 9/3/10 17:16 CDT, bearophile wrote: Andrei Alexandrescu: For classes this must be an rvalue. OK. Why? If you could change this from within a method you'd pretty much ruin everything about object orientation. Andrei

Re: this as lvalue?

2010-09-03 Thread Jonathan M Davis
On Friday 03 September 2010 15:18:25 Andrei Alexandrescu wrote: > On 9/3/10 17:16 CDT, bearophile wrote: > > Andrei Alexandrescu: > >> For classes this must be an rvalue. > > > > OK. Why? > > If you could change this from within a method you'd pretty much ruin > everything about object orientatio

Re: this as lvalue?

2010-09-04 Thread KennyTM~
On Sep 4, 10 05:22, Andrei Alexandrescu wrote: On 9/3/10 16:03 CDT, bearophile wrote: JMRyan: Is this a bug in the compiler (v.2.047)? Am I missing something in thinking it shouldn't be? I think it's not a bug. It's not a common need, but a method may way want to swap this with another. In Ph

Re: this as lvalue?

2010-09-04 Thread Jonathan M Davis
On Saturday 04 September 2010 01:32:03 KennyTM~ wrote: > On Sep 4, 10 05:22, Andrei Alexandrescu wrote: > > On 9/3/10 16:03 CDT, bearophile wrote: > >> JMRyan: > >>> Is this a bug in the compiler (v.2.047)? Am I missing something in > >>> thinking it shouldn't be? > >> > >> I think it's not a bug.

Re: this as lvalue?

2010-09-04 Thread Andrei Alexandrescu
On 9/4/10 3:32 CDT, KennyTM~ wrote: On Sep 4, 10 05:22, Andrei Alexandrescu wrote: On 9/3/10 16:03 CDT, bearophile wrote: JMRyan: Is this a bug in the compiler (v.2.047)? Am I missing something in thinking it shouldn't be? I think it's not a bug. It's not a common need, but a method may way

Re: this as lvalue?

2010-09-04 Thread Andrei Alexandrescu
On 09/04/2010 10:41 AM, Steven Schveighoffer wrote: Andrei Alexandrescu Wrote: On 9/3/10 16:03 CDT, bearophile wrote: JMRyan: Is this a bug in the compiler (v.2.047)? Am I missing something in thinking it shouldn't be? I think it's not a bug. It's not a common need, but a method may way wa

Re: this as lvalue?

2010-09-04 Thread Steven Schveighoffer
Andrei Alexandrescu Wrote: > On 9/3/10 16:03 CDT, bearophile wrote: > > JMRyan: > >> Is this a bug in the compiler (v.2.047)? Am I missing something in > >> thinking it shouldn't be? > > > > I think it's not a bug. It's not a common need, but a method may way want > > to swap this with another.

Re: this as lvalue?

2010-09-05 Thread JMRyan
Andrei Alexandrescu wrote in news:i5rovm$1q4...@digitalmars.com: > > For classes this must be an rvalue. > > Andrei I reported this as issue 4819.

Re: this as lvalue?

2010-09-05 Thread Andrej Mitrovic
Does this mean assigning to fields won't be an option anymore when using this? E.g.: class Foo { int x; int y; void changeXY(int x, int y) { this.x = x; this.y = y; } } On Sun, Sep 5, 2010 at 6:09 PM, JMRyan wrote: > Andrei Alexandrescu wrote in > news:i5ro

Re: this as lvalue?

2010-09-05 Thread Andrej Mitrovic
Gmail likes to eat my code for some reason, it just ate two closing parantheses.. lol. On Mon, Sep 6, 2010 at 12:02 AM, Andrej Mitrovic wrote: > Does this mean assigning to fields won't be an option anymore when using this? > > E.g.: > > class Foo > { >    int x; >    int y; > >    void changeXY(

Re: this as lvalue?

2010-09-05 Thread Jonathan M Davis
On Sunday 05 September 2010 15:02:10 Andrej Mitrovic wrote: > Does this mean assigning to fields won't be an option anymore when using > this? > > E.g.: > > class Foo > { > int x; > int y; > > void changeXY(int x, int y) > { > this.x = x; > this.y = y; > } > }

Re: this as lvalue?

2010-09-05 Thread Andrej Mitrovic
Ok, thanks. I never liked the "lvalue rvalue" names.. For example http://en.wikipedia.org/wiki/Value_%28computer_science%29 l-value, non-lvalue, rvalue, nonlvalue.. bleh. It's the same thing as when I see "mutable, non-immutable, non-mutable, immutable" sprinkled with a few tripple negatives all a

Re: this as lvalue?

2010-09-05 Thread Andrei Alexandrescu
On 09/05/2010 05:02 PM, Andrej Mitrovic wrote: Does this mean assigning to fields won't be an option anymore when using this? E.g.: class Foo { int x; int y; void changeXY(int x, int y) { this.x = x; this.y = y; } } No, guys, most everything will be

Re: this as lvalue?

2010-09-05 Thread bearophile
Andrei: > If you can write (new Foo).x = x, then you can also write this.x = x. Try it > now! See my bug reports/enhancement requests (about three days ago in a program of mine I have added a bug that enhancement 4407 is able to avoid): Arguments and attributes with the same name http://d.purem

Re: this as lvalue?

2010-09-05 Thread Andrej Mitrovic
++ on that bug report. On a similar note, today I was rewriting a dsource class example because I wanted to show that you can use "this.name" to assign to fields that have the same name as a parameter. And then I accidentally made this mistake when writing a different method: class Foo { stri

Re: this as lvalue?

2010-09-06 Thread bearophile
Andrej Mitrovic: > ++ on that bug report. Then vote for it :-) Bye, bearophile

Re: this as lvalue?

2010-09-06 Thread Andrej Mitrovic
Done. I only have 5 votes left though. This is no democracy!! :p On Mon, Sep 6, 2010 at 12:58 PM, bearophile wrote: > Andrej Mitrovic: >> ++ on that bug report. > > Then vote for it :-) > > Bye, > bearophile >