mixin troubles

Derek Parnell derek at nomail.afraid.org
Thu Oct 5 17:43:59 PDT 2006


On Thu, 05 Oct 2006 18:55:44 -0500, Josh Stern wrote:

>   mixin .FFoo!(a) x;  // bring in the statement in the 'x' sub-namespace

Thank you. This was the key information that I didn't pick up from the
docs. It is documented but I didn't get it until now. The important passage
from the docs is "A mixin has its own scope". I kept on reading that as
"the mixin's template has its own scope" but now I understand it is the
mixin statement itself that creates a new scope/namespace, and that the
"MixinIdentifier" is the optional name one can give to that scope. Then one
can use the MixinIdentifier as a namespace qualifier to disambiguate
identifiers brought in by the mixin statements.

Mind you, this would have been made easier if the 'alias' argument could
also have been used to 'set' the identifier declared in the template.

In other words it would have been 'smart' for mixin to allow ...

 template foo(alias a, alias b)
 {
    typeof(b) a(b) { . . . }
 }

 mixin foo!(Bar, 3);
 mixin foo!(Qwe, 3.14);


to generate code as ...

    typeof(3) Bar(3) { . . . }
    typeof(3.14) Qwe(3.14) { . . . }

then there would have been no disambiguation required.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
6/10/2006 10:33:50 AM



More information about the Digitalmars-d-learn mailing list