What are AST Macros?

Steven Schveighoffer schveiguy at yahoo.com
Mon Jul 12 04:48:29 PDT 2010


On Sun, 11 Jul 2010 07:01:49 -0400, Don <nospam at nospam.com> wrote:

> retard wrote:
>> Thu, 08 Jul 2010 21:43:57 -0400, Robert Jacques wrote:
>>
>>> Check out Walter's slides and/or talk from the D conference.
>>> (http://www.digitalmars.com/webnews/newsgroups.php?
>> art_group=digitalmars.D.announce&article_id=12555)
>>> AST does stand for abstract syntax tree and they are much more like  
>>> Lisp
>>> macros as opposed to the C preprocessor.
>>  Too bad nothing happened. He promised AST macros, but it will probably  
>> still take several years before we have a preliminary implementation  
>> and maybe 10-20 years before a written spec & almsot bug-free  
>> implementation.
>
> Part of what happened was that at the conference, I showed that the  
> functionality of string mixins was a superset of what was planned for  
> AST macros. Since that time, there has not been any kind of proposal, or  
> even a concept. So it's a bit meaningless to talk about "AST macros"  
> right now as if they were a planned-but-not-yet-implemented feature.

The problem I see with mixins is they are ugly.  The difference between  
mixins and most other parts of the language is the syntax is still  
super-basic.  It would be the equivalent of having to call functions with  
callfunction(funcname, params).  What we need is a way to make mixins look  
like normal expressions.

I proposed at one time to use macro to define easily callable mixins.  It  
was something along the lines of:

macro log(level, x) mixin("if(" ~ level ~ " == log.level){log.output(" ~ x  
~ ")}");

which makes it possible to have lazy logging without the lazy keyword and  
without the ugliness of mixins at the call site.

If people agree that AST macros are superseded by mixins, then why not  
take over the macro keyword (which if restricted to AST macros is  
effectively a dead keyword), and make programmer's lives and generic  
programming easier?

-Steve


More information about the Digitalmars-d mailing list