AST Macros (was: Extended Type Design)

Marcin Kuszczak aarti at interia.pl
Sat Mar 17 05:23:38 PDT 2007


Walter Bright wrote:

> It's pretty simple:
> 
> macro foo(args)
> {
> ...syntax that gets inserted...
> }
> 
> and the args and syntax is evaluated in the context of the invocation of
> the macro, not the definition of the macro. You'll be able to do things
> like:
> 
> macro print(arg)
> {
> writefln(__FILE__, __LINE__, arg);
> }
> 
> which get the file and line in the right context. There's no way to do
> that right now.

And what about mixin templates? Couldn't they just be fixed to do this work? 

>From docs:
" Unlike a template instantiation, a template mixin's body is evaluated
within the scope where the mixin appears, not where the template
declaration is defined. It is analogous to cutting and pasting the body of
the template into the location of the mixin. It is useful for injecting
parameterized 'boilerplate' code, as well as for creating templated nested
functions, which is not possible with template instantiations. "

For me it looks exactly like this what you want to do with macro. 

What would be a difference?

For me it seems that the whole mixin thing is rather buggy and unusfull at
the moment - for reference see:
http://www.digitalmars.com/d/archives/digitalmars/D/learn/3412.html#N3416


-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------




More information about the Digitalmars-d mailing list