Proposal keyword 'outer' (mixins)

Tom S h3r3tic at remove.mat.uni.torun.pl
Mon Jun 26 01:32:20 PDT 2006


Don Clugston wrote:
> It's really important that mixins be able to access outer variables 
> without knowing how deep they are.  I think this is quite different from 
> the situation for inner classes.
> 
> ie, in a mixin, if you had to write
> 
> outer.outer.outer.x
> 
> mixins would lose most of their power.

Wouldn't this be a problem only in case of instantiating mixins 
recursively inside other mixins ? I'd then use an alias in the recursive 
mixin template that brings the required symbol to the mixin's scope, 
like 'private alias outer.foo foo'. Then the nested mixin would only 
have to use 'outer.foo' to get the indefinitely deep symbol.

That combined with my previous proposal: 
http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39135

would make it at least workable...


> I'd be in favour of syntax which said:
> (a) this template is intended for use as a mixin; and

Agreed. 'mixin template foo() {}' or just 'mixin foo() {}' would be much 
more explicit...


> (b) I'm importing the next symbol from _somewhere_ outside the mixin.

This would also be an option for the 'outer' keyword. 'outer.foo' could 
just mean that. Take 'foo' from _somewhere_ outside the mixin.


Thanks for answering... I thought I was the only one concerned about 
mixin visibility rules :/


-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d mailing list