Proposal: Dedicated-string-mixin templates/functions
Nick Sabalausky
a at a.a
Fri Feb 5 03:13:14 PST 2010
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.
More information about the Digitalmars-d
mailing list