Proposal: Dedicated-string-mixin templates/functions

Nick Sabalausky a at a.a
Sat Feb 6 18:53:41 PST 2010


"Yigal Chripun" <yigal100 at gmail.com> wrote in message 
news:hkjnp8$ms9$1 at digitalmars.com...
> 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.
>

You don't see the current "mixin(foo(fooArgs));" as being iffy syntax?


> 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).
>

Absolutely agree with you here. That would be a fairly involved change 
though, and I suspect D being natively compiled may raise more difficulties 
and cross-platform issues than it does in Nemerle as Nemerle is VM-only. 
Would certainly be nice to have that at some point though.





More information about the Digitalmars-d mailing list