Proposal: Dedicated-string-mixin templates/functions

Nick Sabalausky a at a.a
Fri Feb 5 12:32:41 PST 2010


"Simen kjaeraas" <simen.kjaras at gmail.com> wrote in message 
news:op.u7nl710qvxi10f at biotronic-pc.home...
> Nick Sabalausky <a at a.a> 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.
>>
>>
>
> Actually, this is already in Bugzilla.
> ( http://d.puremagic.com/issues/show_bug.cgi?id=3666 )
> And it will probably come as no surprise that I, as creator of that
> request, very much support this.
>

Wow, that's kinda crazy, the same exact suggestion, and honestly I swear I 
never saw that ticket before.

It doesn't mention functions though. With CTFE becoming more and more 
powerful, CTFE is getting used more and more to generate the strings to be 
mixin in. So it should probably apply to functions, too. Do you think that 
should go in the same ticket or in a separate one?

Well, considering two people independantly came up with essentially the same 
exact idea and the exact same reasoning, hopefully that puts more weight 
behind it.






More information about the Digitalmars-d mailing list