mixin bug?

Engine Machine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 11 18:50:17 PDT 2016


On Thursday, 11 August 2016 at 21:03:36 UTC, Ali Çehreli wrote:
> On 08/11/2016 01:27 PM, Engine Machine wrote:
>
> > I see the mixin as a sort of copy and paste.
>
> That's the case for string mixins. Template mixins bring a name 
> resolution scope. My understanding of the topic:
>
>   
> http://ddili.org/ders/d.en/mixin.html#ix_mixin.name%20space,%20mixin
>
> The spec:
>
>   https://dlang.org/spec/template-mixin.html
>
> Ali

"When a mixed-in name is the same as a name that is in the 
surrounding scope, then the name that is in the surrounding scope 
gets used:"

Which is my point, for "2nd order or higher" mixins, this does 
not occur.

The why I see it is that mixin template is sort of like a copy 
and paste, but only paste if the members do not exist 
already(i.e., the current behavior for "1st order" mixins. I 
would expect the same logic to hold for higher order mixins since 
a mixin of a mixin is still a mixin).

I realize why D behaves the way it does, but this is limiting. It 
simply greedily resolves referencing members rather than lazily. 
If the greedy method actually has some desired characteristic, 
then a lazy mixin would be nice.

lazy mixin T1!T;






More information about the Digitalmars-d-learn mailing list