Proposal: Dedicated-string-mixin templates/functions

Yigal Chripun yigal100 at gmail.com
Sat Feb 6 04:36:33 PST 2010


On 05/02/2010 23:24, Trass3r wrote:
>> Proposed:
>> -----------------------
>> mixin template foo1 {
>> const char[] foo1 = "int a;";
>> }
>> mixin char[] foo2() {
>> return "int b;";
>> }
>> foo1!();
>> foo2();
>> -----------------------
>>
>
> Well, it's a little bit indistinctive, hard to tell if it's a normal
> function call or a mixin without e.g. using a mixin prefix for the
> function name (which is nothing better than it is now)
> But an advantage would be that these functions could be omitted in the
> final executable since they are only used at compile-time.

IMO, this is a bad idea.
The most important thing we should get from Nemerle regarding this is 
the much better compilation model and not just the syntax. The syntax 
idea itself is iffy at best especially in the D version.

To contrast with the Nemerle solution:
the "function" foo2 above would be put in a separate file and would be 
compiled *once* into a lib.
Than, at a separate phase,  this lib can be loaded by the compiler and 
used in the client code.
Also, In Nemerle, foo2 is a regular function which means, unlike D, it 
isn't restricted compared to "regular" functions and for example can 
call stdlib functions like the equivalent of "writef" (no need for 
special pragma(msg, ..) constructs).




More information about the Digitalmars-d mailing list