What are AST Macros?

bearophile bearophileHUGS at lycos.com
Mon Jul 12 13:22:28 PDT 2010


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.

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.

In past I have asked for a gensym intrinsic in D, but it was not a serious request, because I don't want to see string mixing used even more in D :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list