Am Mon, 9 Apr 2012 03:38:15 +0300 schrieb Manu <turkey...@gmail.com>:
> On 9 April 2012 03:25, Andrei Alexandrescu > <seewebsiteforem...@erdani.org>wrote: > > > On 4/8/12 7:21 PM, Andrej Mitrovic wrote: > > > >> On 4/9/12, Andrei > >> Alexandrescu<SeeWebsiteForEmai**l...@erdani.org<seewebsiteforem...@erdani.org>> > >> wrote: > >> > >>> and pass-by-alias > >>> > >> > >> Speaking of alias, one killer feature would be to enable using alias > >> for expressions. E.g.: > >> > >> struct Window { struct Point { int x, y; } Point point; } > >> void test() { > >> Window window; > >> alias window.point.x x; > >> // use 'x' here which is really window.point.x > >> } > >> > > > > Yah, we should add that at some point. Walter and I discussed about it and > > it's virtually approved. But to be on the conservative side, it's not for > > expressions but for mere pointer-chasing chains. > > > Why use alias, instead of allowing 'ref' on local declarations? > The alias approach suffers from complications when referencing a complex > expression. Particularly if that expression involves a non-pure function > call. A local ref would seem less problematic to me? This is a valid concern. I remember the discussion from a while back. alias makes it _look_ shorter and right, but you get what Manu said. Here is another look on it: MyClass a = foo(); MyClass x = bar(); alias a.c c1; ref c2 = a.c; a = x; c1 = 5; // <- oops, using x instead of a c2 = 5; // <- more what I expect Not to say alias for 'moving' targets is a no-go, but I'd rather proper refs. :) -- Marco