Sugar around string mixins

Sergey Gromov snake.scaly at gmail.com
Sun Oct 4 07:01:01 PDT 2009


Sat, 3 Oct 2009 21:33:37 -0400, Jarrett Billingsley wrote:

> On Sat, Oct 3, 2009 at 9:22 PM, Sergey Gromov <snake.scaly at gmail.com> wrote:
> 
>> While I like and support the idea, I think that hijacking the "macro"
>> keyword now will make it very hard to re-design later.  It would be much
>> better to reuse the "mixin" keyword for this since it's exactly what's
>> happening: defining a function for mixing in:
>>
>> mixin max(int a, int b) {...}
>>
>> It could be problematic from the grammar perspective though.
> 
> Newp. 'mixin' could be followed by one of four things:
> 
> - '(', it's a string mixin.
> - 'ident' '!', it's a template mixin.
> - 'ident' ';' it's also a template mixin.
> - 'ident' '(', it's a mixin declaration.
> 
> Not tough. But then you're really overloading the keyword by using it
> for three very different purposes.

I cannot see how this is "very different" from what it does currently.
I'm declaring a function intended specifically for mixing in.  That's
what you usually do.  I'm just moving the "mixin" keyword from every
single function invocation to its declaration, reducing the unnecessary
typing and ugliness.

I can see a problem with this approach though, that something that looks
lke a function call can be actually a mixin with full access to the
container function scope.  Explicit mixins are, well, explicit in this
respect.



More information about the Digitalmars-d mailing list