October 06, 2006
On Fri, 06 Oct 2006 10:43:59 +1000, Derek Parnell wrote:

> 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.

You can't use exactly the same name - i.e. mixin .FFoo!(a) a;
But you could adopt some convention of related names - i.e.
mixin .FFoo!(a) for_a;
mixin .FFoo!(b) for_b;

for_a.foo();
for_b.foo();

etc.



> 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.

October 06, 2006
On Fri, 06 Oct 2006 03:43:59 +0300, Derek Parnell <derek@nomail.afraid.org> wrote:

> 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.
>


Yep, that would be very useful.

This feature, i.e. an ability to declare custom identifiers (or part of them) in templates, has been suggested before (not surprisingly). Lets hope that it will be implemented someday. *wink*wink* ;)
1 2
Next ›   Last »