Will macros just be syntactic sugar?

Davidl Davidl at 126.com
Wed Apr 25 03:52:19 PDT 2007


how to emit a error message by CTFE if arg0 is not an
identifier? and compiling that CTFE library would be pretty
much slower compared to my version.
And the advantage of macro is the frontend parser can help
IDE for auto-completion.

> Davidl wrote:
>> macro macroname(Token... tokens)
>> {
>>      static if (tokens[0].ID != Token.LParen)
>>     pragma(error, `( expected`);
> :
>>      alias token[1] arg0;
>>      alias token[5] arg1;
>>      alias token[7] arg2;
>>      alias token[9] arg3;
>>      arg0[arg1] = arg2 + arg3;
>> }
>>  caller could call the macro with :
>>  macroname(arg0)[arg1] := arg2 + arg3;
>
> I don't think that's much nicer than
> mixin(macroname("arg0[arg1]:= arg2+ arg3"));
>
> which works in DMD 1.012. The static if/Token properties can be done via  
> a CTFE library. If structs were allowed in CTFE functions, the code  
> wouldn't even be too ugly.




More information about the Digitalmars-d mailing list