On 02/05/2010 12:13 PM, Nick Sabalausky wrote:
Point #1: It's often been noted that string mixin syntax is ugly. Which is a
bad thing in and of itself, but it also tends to discourage use of string
mixins despite their high degree of usefulness.

Point #2: It seems to me that the vast majority of templates and functions
are either designed specifically to be used as a string mixin or
specifically designed to be used as something other than a string mixin.
Only rarely does a single template or function seem to be particularly
useful both ways.

Proposal:
So how about taking a cue from Nemerle:

Current:
-----------------------
template foo1 {
     const char[] foo1 = "int a;";
}
char[] foo2() {
     return "int b;";
}
mixin(foo1!());
mixin(foo2());
-----------------------

Proposed:
-----------------------
mixin template foo1 {
     const char[] foo1 = "int a;";
}
mixin char[] foo2() {
     return "int b;";
}
foo1!();
foo2();
-----------------------

One consequence of this worth noting is that the current string-mixin could
be trivially recreated under the proposed syntax:

-----------------------
mixin char[] mixinString(char[] str) {
     return str;
}
mixinString("int a;");
-----------------------

Maybe someone not as half-asleep as I currently am can point out a
clean/clever way to retrieve the string value of such a template/function
without actually mixing it in, to cover the occasional cases where that
actually would be useful.



I agree, for the mixin template part at least.

Then we just need a cleaner way to "return" things from templates, and we'll be all good.

Reply via email to