What about an identifier that is an mixin

André Puel via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 13 14:12:55 PST 2017


On Friday, 13 January 2017 at 21:29:28 UTC, Daniel Kozák wrote:
> André Puel via Digitalmars-d <digitalmars-d at puremagic.com> 
> napsal Pá, led 13, 2017 v 10∶15 :
>> One thing that I miss sometimes when doing meta programming is 
>> being able to hide that a function should be called with mixin.
>> 
>> For example (pardon my lack of creativity):
>> 
>>     // Instead of
>>     string declare_a() {
>>         return "int a;"
>>     }
>> 
>>     int func() {
>>         mixin(declare_a);
>>         return a;
>>     }
>> 
>>     // Could we have?
>>     mixin declare_a() {
>>         return "int a;";
>>     }
>> 
>>     int func() {
>>         declare_a;
>>         return a;
>>     }
>> 
>> I think this could be useful when one is creating Idiom and 
>> Patterns, you could hide implementations details.
>
> You can do this:
>
> mixin template declare_a()
> {
>     int a;
> }
>
> int func()
> {
>     mixin declare_a;
>     return a;
> }
>
> but there is no way to exclude mixin before calling declare_a, 
> there is a good reason for that (it is really important to be 
> able to tell when you use mixin and when not)

Could you elaborate on why you consider it important to be able 
to tell when you use mixin and when not?

I know C macro is a mess, but in C you don't know if you are 
calling a function or if it is a macro.

In D, you don't know if a member is a function call or an 
attribute when you access it without parenthesis:

     myObj.a; //Is it a function call or an attribute?

There are these cases where the one developing a 
library/framework want to lie to the programmer using it. It 
makes the feature seamless.


More information about the Digitalmars-d mailing list