What are AST Macros?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jul 12 15:35:05 PDT 2010


On 07/12/2010 03:22 PM, bearophile wrote:
> Steven Schveighoffer:
>> bearophile:
>>> String mixins are a hack, just a bit better than C preprocessor
>>> (because they are scoped), they are not a replacement of clean
>>> macros.
>>
>> Interesting statement, can you back it up? :)  What can you do with
>> a macro that you can't do with a mixin?
>
> In the meantime others have already given you some answers, I can add
> one example. The Brainfuck language allows you to do every kind of
> thing, I have seen even compilers written in it, but its usage is
> very unhandy, it's bug-prone, requires lot of code to do even simple
> things, and it's very hard to modify and debug programs written in
> it. What I meant is that string mixins in theory allow you to do many
> things, but in practice you can't use them for complex tasks, and you
> can't modify and fix the resulting code if you try to use them for
> more complex tasks. They are not a long-term solution for a language
> that seriously wants to improve over C and its preprocessor macros,
> they are a hack.
>
> In my opinion the std.bitmanip.bitfields souce code is already past
> the decency limit for string mixins, and I hope they will be replaced
> by something better.

Clearly a more structured approach would be better. On the other hand 
bitfields is literally the first code-generating tool I ever wrote, so I 
expect better idiomatic code will come about after the community's 
experience increases.

> I don't agree with Andrei when he says that CLisp macros (and even
> more Scheme macros that are hygienic too) are as hairy and
> unmantenable as code that uses string mixins heavily.

I said:

=======
Though I sympathise with all of the above, I should add that I have 
looked at languages that feature AST macros (Lisp, Scheme, Dylan) and 
such macros are difficult to create and read as well. We're not looking 
at day and night improvement there.
=======

and you claim, quite unequivocally, that I said:

=======
CLisp macros (and even more Scheme macros that are hygienic too) are as 
hairy and unmaintainable as code that uses string mixins heavily.
=======

I mean WTF?

Back on topic: http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html. 
Compare the simple macro in the beginning and the correct macro at the end.


Andrei


More information about the Digitalmars-d mailing list