change mixins

Chad J chadjoan at __spam.is.bad__gmail.com
Sun Feb 14 15:47:14 PST 2010


Walter Bright wrote:
> Right now, mixins are defined and used as:
> 
>    template foo(T) { declarations... }
> 
>    mixin foo!(int) handle;
> 
> The proposal is to switch it around:
> 
>    mixin template foo(T) { declarations... }
> 
>    foo!(int) handle;
> 
> to follow the notion that mixin templates are very different from
> regular templates, and that should be reflected in their definition
> rather than use.
> 
> What do you think?

This was discussed once:
http://www.digitalmars.com/d/archives/digitalmars/D/learn/Template_mixins_Why_is_the_decision_to_mixin_made_at_the_call_site_17477.html

At some level I am OK with this.  Too me though, it is more important to
be able to omit the "mixin" keyword at invocation than it is to dictate
it at declaration.  In fact, even that isn't so bad.

I don't think mixin templates are really that much of an issue.  String
mixins are.  The lack of being able to place D statements into the mixin
templates makes them considerably less useful than string mixins.  You
can perform arbitrary (runtime) code with mixin templates of course,
it's just that you have to spawn an enormous number of dummy
declarations to make the wheels turn.  For an example, see this
monstrosity I made long ago:
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=47471&header
That may have been before string mixins.

So I could see moving mixin from use to declaration.  I just don't think
I would care about it nearly as much as this:
http://www.digitalmars.com/d/archives/digitalmars/D/Proposal_Dedicated-string-mixin_templates_functions_105748.html

Note that with good string mixin syntax, we could have something like

	int foo = 42;
	string bar = "answer";
	
	writefln("The $bar is $foo."); // Prints "The answer is 42."

OR
	writefln#("The $bar is $foo."); // Prints "The answer is 42."
	// Use this syntax if it needs to be greppable.
	// Nothing says it has to be # either.

The other usecase for that which came up recently was sql queries.  I
suppose my point in all of this is that you can probably make much
better gains by messing with mixin syntax in a different way.



More information about the Digitalmars-d mailing list