January 29, 2013
On Monday, 28 January 2013 at 19:55:48 UTC, Jacob Carlborg wrote:
> On 2013-01-28 15:00, Maxim Fomin wrote:
>
>> Returning void instead of int in the example break assignment chaining a
>> = b = c. Besides, how such implicitly defined functions may call user
>> defined code (check input validity, call events, etc.)?
>
> No, the compiler should do a rewrite, as follows:
>
> class Foo
> {
>     int bar_;
>
>     @property int bar () { return bar_; }
>     @property void bar (int value) { bar_ = value; }
> }
>
> auto foo = new Foo;
> int a = foo.bar = 3;
>
> The above line should be rewritten as:
>
> foo.bar = 3;
> int a = foo.bar;

No, it should be rewritten as foo.bar = 3, int a = 3 or int a = foo.bar._set(3). Your example calls getter, which breaks C and D assignment rules, and contradicts to C# property implementation as was said in this thread in previous posts.

> The compiler also need to rewrite the following:
>
> struct Bar
> {
>     int a;
> }
>
> class Foo
> {
>     Bar bar_;
>
>     @property Bar bar () { return bar_; }
>     @property void bar (Bar value) { bar_ = value; }
> }
>
> auto foo = new Foo;
> foo.bar.a = 3;
>
> The above line should be rewritten to:
>
> auto __tmp = foo.bar;
> __tmp.a = 3;
> foo.bar = __tmp;
>
> If not, the value of "foo.bar.a" hasn't really changed since you returned a copy by value. If you instead return by reference you can bypass the setter using the getter.

This is reasonable.
January 29, 2013
> [1] If you think the required '()' in UFCS chains look ugly, you're right, but the
> right fix isn't to butcher the language. '()' carry important information. Having
> a mode where function calls are made w/o the parens would be a good idea, but it
> should be limited to an explicit scope. ie something like
> "auto r = function {generator(x, y, z).map!(x => x * x)};", except 'function' keyword
> can't be overloaded like that, it's too long, and ()-less calls isn't the only change
> that could be done.

I think having some kind of pipe operator would be a better solution. But it's probably too late to add any of those now.
January 29, 2013
> I think having some kind of pipe operator would be a better solution. But it's probably too late to add any of those now.

I'm sorry, I didn't realize I was replying to a two months old post.
January 29, 2013
On Monday, 19 November 2012 at 06:53:46 UTC, Andrei Alexandrescu wrote:
> On 11/19/12 1:16 AM, Jonathan M Davis wrote:
>> On Monday, November 19, 2012 07:02:03 Rob T wrote:
> I think UFCS changes the playfield quite a lot. Code using UFCS looks a whole lot crappier with a bunch of arbitrary extra parens.

As I've been saying: make parens optional only if the function is followed by a dot. Otherwise, make parens compulsory for functions:

function1.function2.function3(); //allowed

function1(); //allowed

function1; // forbidden

@property-ies should be forbidden to use paranthesis, no matter the context.
5 6 7 8 9 10 11 12 13 14 15
Next ›   Last »