Properties: a.b.c = 3

2009-07-28 Thread Walter Bright
The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing with this. One thought I had was

Re: Properties: a.b.c = 3

2009-07-28 Thread Ary Borenszweig
Walter Bright escribió: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing with this

Re: Properties: a.b.c = 3

2009-07-28 Thread BLS
Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing with this.

Re: Properties: a.b.c = 3

2009-07-28 Thread Walter Bright
BLS wrote: What I don't see is why a property isn't just a property. What you announce is more a kind of "universal maybe these value holder" - a temporary object is not a property period Even returning an 'int' is a temporary object.

Re: Properties: a.b.c = 3

2009-07-28 Thread BLS
BLS wrote: Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing

Re: Properties: a.b.c = 3

2009-07-28 Thread BLS
Walter Bright wrote: BLS wrote: What I don't see is why a property isn't just a property. What you announce is more a kind of "universal maybe these value holder" - a temporary object is not a property period Even returning an 'int' is a temporary object. ?

Re: Properties: a.b.c = 3

2009-07-28 Thread Andrei Alexandrescu
BLS wrote: BLS wrote: Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value

Re: Properties: a.b.c = 3

2009-07-28 Thread davidl
在 Wed, 29 Jul 2009 10:33:53 +0800,Walter Bright 写道: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds

Re: Properties: a.b.c = 3

2009-07-28 Thread BLS
Andrei Alexandrescu wrote: BLS wrote: BLS wrote: Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special pr

Re: Properties: a.b.c = 3

2009-07-28 Thread Daniel Keep
Walter Bright wrote: > The issue is what if b is a property, returns a temporary object, and > that temp's .c field is uselessly set to 3? > > It's a classic problem with properties that are implemented as functions. > > I don't see how C#'s special property syntax adds any value for dealing >

Re: Properties: a.b.c = 3

2009-07-28 Thread Jarrett Billingsley
On Tue, Jul 28, 2009 at 10:33 PM, Walter Bright wrote: > The issue is what if b is a property, returns a temporary object, and that > temp's .c field is uselessly set to 3? So, the issue is that 'a.b()' returns a struct by value. Such return values should always be considered rvalues. Furthermor

Re: Properties: a.b.c = 3

2009-07-28 Thread Nick Sabalausky
"BLS" wrote in message news:h4oeb0$5s...@digitalmars.com... > Walter Bright wrote: >> BLS wrote: >>> What I don't see is why a property isn't just a property. What you >>> announce is more a kind of "universal maybe these value holder" >>> - a temporary object is not a property period >> >> Even

Re: Properties: a.b.c = 3

2009-07-28 Thread Nick Sabalausky
"Daniel Keep" wrote in message news:h4og1p$b3...@digitalmars.com... > > Walter Bright wrote: >> The issue is what if b is a property, returns a temporary object, and >> that temp's .c field is uselessly set to 3? >> >> It's a classic problem with properties that are implemented as functions. >> >

Re: Properties: a.b.c = 3

2009-07-28 Thread Walter Bright
davidl wrote: A property should never return temp obj in the first place. That's unworkable - it means you cannot have user defined types.

Re: Properties: a.b.c = 3

2009-07-28 Thread Chad J
Daniel Keep wrote: > > Walter Bright wrote: >> The issue is what if b is a property, returns a temporary object, and >> that temp's .c field is uselessly set to 3? >> >> It's a classic problem with properties that are implemented as functions. >> >> I don't see how C#'s special property syntax add

Re: Properties: a.b.c = 3

2009-07-28 Thread Daniel Keep
Jarrett Billingsley wrote: > On Tue, Jul 28, 2009 at 10:33 PM, Walter > Bright wrote: >> The issue is what if b is a property, returns a temporary object, and that >> temp's .c field is uselessly set to 3? > > So, the issue is that 'a.b()' returns a struct by value. Such return > values should

Re: Properties: a.b.c = 3

2009-07-29 Thread Kagamin
Walter Bright Wrote: > The issue is what if b is a property, returns a temporary object, and > that temp's .c field is uselessly set to 3? > > It's a classic problem with properties that are implemented as functions. Does this problem pertain to properties? Look at this: void main() { int a=

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Kagamin wrote: Walter Bright Wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. Does this problem pertain to properties? Look at this: void main()

Re: Properties: a.b.c = 3

2009-07-29 Thread Kagamin
Andrei Alexandrescu Wrote: > The code above is only loosely related. The code above contains a > definition initiated by the user. True, but is there any technical difference for compiler? How the usefulness of the code change depending on whether it's written by the user or... huh?.. don't kn

Re: Properties: a.b.c = 3

2009-07-29 Thread Zhenyu Zhou
Daniel Keep Wrote: > Maybe the compiler could rewrite the above as: > > auto t = a.b; > t.c = 3; > a.b = t; > > Unless it can prove it doesn't need to. Same solution as to the op= > conundrum. I think b should be const if it is a temporary object. And the compiler will tell you that a.b.c is

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Kagamin wrote: Andrei Alexandrescu Wrote: The question is very simple: given that we're used with a specific semantics for a.b.c = 3, how can we address the fact that the semantics of this familiar operation is so different (and likely so useless) when properties replace fields? You're solvi

Re: Properties: a.b.c = 3

2009-07-29 Thread Lionello Lunesu
"Ary Borenszweig" wrote in message news:h4ocm1$28...@digitalmars.com... Walter Bright escribió: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don'

Re: Properties: a.b.c = 3

2009-07-29 Thread Kagamin
Andrei Alexandrescu Wrote: > Kagamin wrote: > > Andrei Alexandrescu Wrote: > >> The question is very simple: given that we're used with a specific > >> semantics for a.b.c = 3, how can we address the fact that the semantics > >> of this familiar operation is so different (and likely so useless)

Re: Properties: a.b.c = 3

2009-07-29 Thread BLS
Walter Bright wrote: davidl wrote: A property should never return temp obj in the first place. That's unworkable - it means you cannot have user defined types. I would like to say that if a class/ structure _is_ a property than it has to be declared as immutable, otherwise it is _not_ a pro

Re: Properties: a.b.c = 3

2009-07-29 Thread KennyTM~
Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing with this.

Re: Properties: a.b.c = 3

2009-07-29 Thread KennyTM~
Lionello Lunesu wrote: "Ary Borenszweig" wrote in message news:h4ocm1$28...@digitalmars.com... Walter Bright escribió: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implement

Re: Properties: a.b.c = 3

2009-07-29 Thread Michel Fortin
On 2009-07-28 22:33:53 -0400, Walter Bright said: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. With the local namespace approach I propsed a little

Re: Properties: a.b.c = 3

2009-07-29 Thread Franklin Minty
BLS Wrote: > Andrei Alexandrescu wrote: > > BLS wrote: > >> BLS wrote: > >>> Walter Bright wrote: > The issue is what if b is a property, returns a temporary object, > and that temp's .c field is uselessly set to 3? > > It's a classic problem with properties that are implement

Re: Properties: a.b.c = 3

2009-07-29 Thread Jarrett Billingsley
On Wed, Jul 29, 2009 at 1:08 AM, Daniel Keep wrote: > > > Jarrett Billingsley wrote: >> On Tue, Jul 28, 2009 at 10:33 PM, Walter >> Bright wrote: >>> The issue is what if b is a property, returns a temporary object, and that >>> temp's .c field is uselessly set to 3? >> >> So, the issue is that 'a.

Re: Properties: a.b.c = 3

2009-07-29 Thread grauzone
Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as to the op= conundrum. Yes! At least that's what the user wants. The compiler has to detect, that the object was modified at all. (To kn

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Kagamin wrote: Andrei Alexandrescu Wrote: Kagamin wrote: Andrei Alexandrescu Wrote: The question is very simple: given that we're used with a specific semantics for a.b.c = 3, how can we address the fact that the semantics of this familiar operation is so different (and likely so useless) whe

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Michel Fortin wrote: On 2009-07-28 22:33:53 -0400, Walter Bright said: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. With the local namespace appro

Re: Properties: a.b.c = 3

2009-07-29 Thread Denis Koroskin
On Wed, 29 Jul 2009 18:36:07 +0400, Andrei Alexandrescu wrote: Kagamin wrote: Andrei Alexandrescu Wrote: Kagamin wrote: Andrei Alexandrescu Wrote: The question is very simple: given that we're used with a specific semantics for a.b.c = 3, how can we address the fact that the semantics of

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Kagamin wrote: Andrei Alexandrescu Wrote: Kagamin wrote: Andrei Alexandrescu Wrote: The question is very simple: given that we're used with a specific semantics for a.b.c = 3, how can we address the fact that the semantics of this familiar operation is so different

Re: Properties: a.b.c = 3

2009-07-29 Thread Jarrett Billingsley
On Wed, Jul 29, 2009 at 10:44 AM, Ary Borenszweig wrote: > Andrei Alexandrescu wrote: >> >> Kagamin wrote: >>> >>> Andrei Alexandrescu Wrote: >>> Kagamin wrote: > > Andrei Alexandrescu Wrote: >> >> The question is very simple: given that we're used with a >> specific semant

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 9:23 AM, Jarrett Billingsley wrote: > On Wed, Jul 29, 2009 at 10:44 AM, Ary Borenszweig > wrote: >> Andrei Alexandrescu wrote: >>> >>> Kagamin wrote: Andrei Alexandrescu Wrote: > Kagamin wrote: >> >> Andrei Alexandrescu Wrote: >>> >>> The

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Tue, 28 Jul 2009 22:33:53 -0400, Walter Bright wrote: The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? There's one way you could do it -- since the return value is a temporary, it should not be an lvalue. But it's membe

Re: Properties: a.b.c = 3

2009-07-29 Thread BCS
Reply to Walter, The issue is what if b is a property, returns a temporary object, and that temp's .c field is uselessly set to 3? It's a classic problem with properties that are implemented as functions. I don't see how C#'s special property syntax adds any value for dealing with this. One t

Re: Properties: a.b.c = 3

2009-07-29 Thread KennyTM~
Bill Baxter wrote: On Wed, Jul 29, 2009 at 9:23 AM, Jarrett Billingsley wrote: On Wed, Jul 29, 2009 at 10:44 AM, Ary Borenszweig wrote: Andrei Alexandrescu wrote: Kagamin wrote: Andrei Alexandrescu Wrote: Kagamin wrote: Andrei Alexandrescu Wrote: The question is very simple: given that we

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 10:11 AM, KennyTM~ wrote: > Bill Baxter wrote: >> >> On Wed, Jul 29, 2009 at 9:23 AM, Jarrett >> Billingsley wrote: >>> >>> On Wed, Jul 29, 2009 at 10:44 AM, Ary Borenszweig >>> wrote: Andrei Alexandrescu wrote: > > Kagamin wrote: >> >> Andrei Alexa

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 10:11 AM, KennyTM~ wrote: > Bill Baxter wrote: >> >> On Wed, Jul 29, 2009 at 9:23 AM, Jarrett >> Billingsley wrote: >>> >>> On Wed, Jul 29, 2009 at 10:44 AM, Ary Borenszweig >>> wrote: Andrei Alexandrescu wrote: > > Kagamin wrote: >> >> Andrei Alexa

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Ary Borenszweig wrote: > Andrei Alexandrescu wrote: >> Kagamin wrote: >>> Andrei Alexandrescu Wrote: >>> Kagamin wrote: > Andrei Alexandrescu Wrote: >> The question is very simple: given that we're used with a >> specific semantics for a.b.c = 3, how can we address the fact >>

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 13:22:14 -0400, Bill Baxter wrote: Similarly, taking the address should lead to an error. auto ptr = &a.b; // ok if b is a field auto ptr = &a.b; // bogus if b is a property returning a non-lvalue Impossible with the current implementation -- &a.b is a delegate :) -Stev

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 10:26 AM, Steven Schveighoffer wrote: > On Wed, 29 Jul 2009 13:22:14 -0400, Bill Baxter wrote: > >> Similarly, taking the address should lead to an error. >> >> auto ptr = &a.b;  // ok if b is a field >> auto ptr = &a.b; // bogus if b is a property returning a non-lvalue >

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 10:36 AM, Bill Baxter wrote: > On Wed, Jul 29, 2009 at 10:26 AM, Steven > Schveighoffer wrote: >> On Wed, 29 Jul 2009 13:22:14 -0400, Bill Baxter wrote: >> >>> Similarly, taking the address should lead to an error. >>> >>> auto ptr = &a.b;  // ok if b is a field >>> auto pt

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether you have properties or not, and needs a solution whether you have properties or not. Well the problem is

Re: Properties: a.b.c = 3

2009-07-29 Thread Sergey Gromov
Wed, 29 Jul 2009 13:39:50 +1000, Daniel Keep wrote: > Walter Bright wrote: >> The issue is what if b is a property, returns a temporary object, and >> that temp's .c field is uselessly set to 3? >> >> It's a classic problem with properties that are implemented as functions. >> >> I don't see how

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether you have properties or not, and needs a solution whether you have properties o

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Ary Borenszweig wrote: Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether you have properties or not, and needs a solution wheth

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as to the op= conundrum. Yes! At least that's what the u

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as to the op= conundrum. Yes! At least that's what the user wants. The compiler has

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 10:50 AM, Andrei Alexandrescu wrote: > Bill Baxter wrote: >> >> Yeh, I don't understand how any of this has anything to do with >> properties.  It's the same question if you ask what should >> >>  a.b().c = 5 >> >>  do.  It's the same issue whether you have properties or not

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 11:08 AM, Andrei Alexandrescu wrote: > >> I don't believe the problem needs to be solved. > > To me it looks like an essential problem. It's a problem, but not a problem of properties. Just a problem of temporary return values in general. --bb

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether you have properties or not

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Bill Baxter wrote: On Wed, Jul 29, 2009 at 10:50 AM, Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether you have properties or n

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Ary Borenszweig wrote: Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whether yo

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: It would be nice if the compiler could help by simply rejecting what it can reject (assignment to rvalues), but other than that, there's not much that can be done. This can be detected in simple ca

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Bill Baxter wrote: On Wed, Jul 29, 2009 at 11:08 AM, Andrei Alexandrescu wrote: I don't believe the problem needs to be solved. To me it looks like an essential problem. It's a problem, but not a problem of properties. Just a problem of temporary return values in general. Yes. It is partic

Re: Properties: a.b.c = 3

2009-07-29 Thread grauzone
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as to the op= conundrum. Yes! At least that's what the u

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Steven Schveighoffer wrote: > On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: > >> Daniel Keep wrote: >>> Maybe the compiler could rewrite the above as: >>> auto t = a.b; >>> t.c = 3; >>> a.b = t; >>> Unless it can prove it doesn't need to. Same solution as to the op= >>> conundrum. >> >>

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:22:26 -0400, grauzone wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Bill Baxter wrote: On Wed, Jul 29, 2009 at 10:50 AM, Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should a.b().c = 5 do. It's the same issue whet

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
grauzone wrote: > Steven Schveighoffer wrote: >> On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: >> >>> Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to. Same solution as to the

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig wrote: a.b.c = d; If b is anything that has a struct type, and c is anything else, the statement must report an error. struct S { int *x; void c(int n) {*x = n;} } struct S2 { int n; S b() { return S(&n);} } void main() { S2

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig wrote: a.b.c = d; If b is anything that has a struct type, and c is anything else, the statement must report an error. struct S { int *x; void c(int n) {*x = n;} } struct S2 { int n; S b() { return S(

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig wrote: a.b.c = d; If b is anything that has a struct type, and c is anything else, the statement must report an error. struct S { int *x; v

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:46:11 -0400, Chad J wrote: grauzone wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn't need to.

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Steven Schveighoffer wrote: > On Wed, 29 Jul 2009 14:46:11 -0400, Chad J > wrote: > >> grauzone wrote: >>> Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: > Daniel Keep wrote: >> Maybe the compiler could rewrite the above as: >> auto t = a.b

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig wrote: a.b.c = d; If b is anything that has a struct type, and c is anything else, the statement must report an error. struct S { int *x; v

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Steven Schveighoffer Wrote: > On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig > wrote: > > > Steven Schveighoffer wrote: > >> On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig > >> wrote: > >> > >>> a.b.c = d; > >>> > >>> If b is anything that has a struct type, and c is anything else

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Steven Schveighoffer wrote: > On Wed, 29 Jul 2009 14:22:26 -0400, grauzone wrote: > >> Steven Schveighoffer wrote: >>> On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: >>> Daniel Keep wrote: > Maybe the compiler could rewrite the above as: > auto t = a.b; > t.c = 3; > a.

Re: Properties: a.b.c = 3

2009-07-29 Thread grauzone
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:22:26 -0400, grauzone wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t = a.b; t.c = 3; a.b = t; Unless it can prove it doesn'

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: It would be nice if the compiler could help by simply rejecting what it can reject (assignment to rvalues), but other than that, there's not much that can be done. This ca

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Chad J wrote: > Steven Schveighoffer wrote: >> Wouldn't the compiler write: >> >> //widget.rect.w = 200 translates to >> auto tmp1 = widget.rect; >> tmp1.w = 200; >> widget.rect = tmp1; >> >> //widget.rect.h = 100 translates to >> auto tmp2 = widget.rect; >> tmp2.h = 100; >> widget.rect = tmp2; >>

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Ary Borenszweig wrote: Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Ary Borenszweig wrote: Andrei Alexandrescu wrote: Bill Baxter wrote: Yeh, I don't understand how any of this has anything to do with properties. It's the same question if you ask what should

Re: Properties: a.b.c = 3

2009-07-29 Thread Ary Borenszweig
Andrei Alexandrescu wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: It would be nice if the compiler could help by simply rejecting what it can reject (assignment to rvalues), but other than that, there's not muc

Re: Properties: a.b.c = 3

2009-07-29 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig wrote: a.b.c = d; If b is anything that has a struct type, and c is anything else, the statement must report an error. struct S { int *x; void c(int n) {*x = n;} } struct S2 { int n; S b() { return S(

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
grauzone wrote: > Steven Schveighoffer wrote: >> option 2, return a special struct which uses properties to set the >> values in the original widget. > > Now this would generate a mess (lots of bloat). Now I'm not sure; maybe > macros could provide a way out (auto generate the code bloat), or > po

Re: Properties: a.b.c = 3

2009-07-29 Thread Rainer Deyke
Andrei Alexandrescu wrote: > Ary Borenszweig wrote: >> Not if b[5] is a struct. Do I need to list evey possible syntax there >> it to get my point clear? :-( > > Yes, you actually need to. It was the point of my post. Simple rule: rvalues cannot be modified (i.e. rvalues are implicitly const). N

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Chad J wrote: > Steven Schveighoffer wrote: >> On Wed, 29 Jul 2009 14:22:26 -0400, grauzone wrote: >> >>> Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: > Daniel Keep wrote: >> Maybe the compiler could rewrite the above as: >> auto t = a.b;

Re: Properties: a.b.c = 3

2009-07-29 Thread grauzone
Chad J wrote: Thinking about it a little more, the extra temporaries could run you out of registers. That still sounds like a negligable cost in most code. Temporaries can be on the stack. That's not a problem.

Re: Properties: a.b.c = 3

2009-07-29 Thread KennyTM~
Andrei Alexandrescu wrote: Bill Baxter wrote: On Wed, Jul 29, 2009 at 11:08 AM, Andrei Alexandrescu wrote: I don't believe the problem needs to be solved. To me it looks like an essential problem. It's a problem, but not a problem of properties. Just a problem of temporary return values in

Re: Properties: a.b.c = 3

2009-07-29 Thread Bill Baxter
On Wed, Jul 29, 2009 at 1:14 PM, grauzone wrote: > Chad J wrote: >> >> Thinking about it a little more, the extra temporaries could run you out >> of registers.  That still sounds like a negligable cost in most code. > > Temporaries can be on the stack. That's not a problem. > How is that not a pe

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Bill Baxter wrote: > On Wed, Jul 29, 2009 at 1:14 PM, grauzone wrote: >> Chad J wrote: >>> Thinking about it a little more, the extra temporaries could run you out >>> of registers. That still sounds like a negligable cost in most code. >> Temporaries can be on the stack. That's not a problem. >>

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Chad J wrote: > Bill Baxter wrote: >> On Wed, Jul 29, 2009 at 1:14 PM, grauzone wrote: >>> Chad J wrote: Thinking about it a little more, the extra temporaries could run you out of registers. That still sounds like a negligable cost in most code. >>> Temporaries can be on the stack. That

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 15:00:42 -0400, Ary Borenszweig wrote: Steven Schveighoffer Wrote: On Wed, 29 Jul 2009 14:50:42 -0400, Ary Borenszweig wrote: > Steven Schveighoffer wrote: >> On Wed, 29 Jul 2009 14:39:07 -0400, Ary Borenszweig >> wrote: >> >>> a.b.c = d; >>> >>> If b is anything th

Re: Properties: a.b.c = 3

2009-07-29 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 15:01:47 -0400, Chad J wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:22:26 -0400, grauzone wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 10:16:33 -0400, grauzone wrote: Daniel Keep wrote: Maybe the compiler could rewrite the above as: auto t

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Steven Schveighoffer wrote: > On Wed, 29 Jul 2009 15:01:47 -0400, Chad J > wrote: >> >> So we could have semantics that actually work, but you don't want them >> because, oh man, my code might have to do a few more assignments. A few >> assignments. Really?! > > Hold on a second, don't we alrea

Re: Properties: a.b.c = 3

2009-07-29 Thread Zhenyu Zhou
Chad J Wrote: > Currently there are some cases where the current paradigm forces you to > do that kind of work by hand: > > struct Rectangle > { > float x,y,w,h; > } > class Widget > { > Rectangle _rect; > Rectangle rect() { return _rect; } > Rectangle rect(Rectangle r) { r

Re: Properties: a.b.c = 3

2009-07-29 Thread Chad J
Zhenyu Zhou wrote: > > What about: > > class Widget > { > Rectangle _rect; > immutable(Rectangle) rect() const { return _rect; } > Rectangle rect(Rectangle r) { return _rect = r; } > } You'll fall into the trap unless you know about immutable. Said another way: the default is

Re: Properties: a.b.c = 3

2009-07-29 Thread Zhenyu Zhou
Chad J Wrote: > Zhenyu Zhou wrote: > > > > What about: > > > > class Widget > > { > > Rectangle _rect; > > immutable(Rectangle) rect() const { return _rect; } > > Rectangle rect(Rectangle r) { return _rect = r; } > > } > > You'll fall into the trap unless you know about immutable. S

Re: Properties: a.b.c = 3

2009-07-30 Thread Chad J
Zhenyu Zhou wrote: > Chad J Wrote: >> Zhenyu Zhou wrote: >>> What about: >>> >>> class Widget >>> { >>> Rectangle _rect; >>> immutable(Rectangle) rect() const { return _rect; } >>> Rectangle rect(Rectangle r) { return _rect = r; } >>> } >> You'll fall into the trap unless you know about

Re: Properties: a.b.c = 3

2009-07-30 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 18:27:09 -0400, Chad J wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 15:01:47 -0400, Chad J wrote: So we could have semantics that actually work, but you don't want them because, oh man, my code might have to do a few more assignments. A few assignments.

Re: Properties: a.b.c = 3

2009-07-30 Thread Steven Schveighoffer
On Wed, 29 Jul 2009 15:14:04 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: It would be nice if the compiler could help by simply rejecting what it can reject (assignment to rvalu

Re: Properties: a.b.c = 3

2009-07-30 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Wed, 29 Jul 2009 15:14:04 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu wrote: Steven Schveighoffer wrote: It would be nice if the compiler could help by simply rejecting what it can r

Re: Properties: a.b.c = 3

2009-07-30 Thread Jimbob
"Walter Bright" wrote in message news:h4ocet$27...@digitalmars.com... > The issue is what if b is a property, returns a temporary object, and that > temp's .c field is uselessly set to 3? > > It's a classic problem with properties that are implemented as functions. > > I don't see how C#'s spec

Re: Properties: a.b.c = 3

2009-07-30 Thread Nick Sabalausky
"Zhenyu Zhou" wrote in message news:h4rfif$2os...@digitalmars.com... > > e.g. > Rectangle rect(Rectangle r) { > _rect = r; > redraw(); > return _rect; > } > > If you allow > widget.rect.w = 200; > widget.rect.h = 100; > you will have to write much more code to handle the painting correctly. >

Re: Properties: a.b.c = 3

2009-07-30 Thread Steven Schveighoffer
On Thu, 30 Jul 2009 14:09:06 -0400, Nick Sabalausky wrote: "Zhenyu Zhou" wrote in message news:h4rfif$2os...@digitalmars.com... e.g. Rectangle rect(Rectangle r) { _rect = r; redraw(); return _rect; } If you allow widget.rect.w = 200; widget.rect.h = 100; you will have to write much more

Re: Properties: a.b.c = 3

2009-07-30 Thread Nick Sabalausky
"Chad J" wrote in message news:h4oku0$ue...@digitalmars.com... > Daniel Keep wrote: >> >> Maybe the compiler could rewrite the above as: >> >> auto t = a.b; >> t.c = 3; >> a.b = t; >> > > I'd always suspected C# properties did something like this, though it's > been so long since I've used C# now

  1   2   >