Abstract syntax tree manipulation

Araq rumpf_a at web.de
Mon Apr 22 09:42:58 PDT 2013


> Beyond AST macros, Nimrod ( http://nimrod-code.org ) has text 
> substituation mechanisms called templates - much like C macros 
> or templates in C++ and D. It also has term rewriting macros.

Nimrod's templates do operate on the AST too, they don't perform 
text substitution.

> In my opinion, Nimrod is a language where a lot of features can 
> produce dirty code ( although some of them are very well done 
> and they are extremely powerful tools ), and it's the 
> developer's choice to use the features for the right purposes ( 
> especially true with term rewriting ).

Term rewriting macros can be turned off on both local and global 
levels to ensure they don't affect semantics. You can also 
exclude a TR macro symbol explicitly in an "import" statement 
(import module except broken_tr_macro)  should the transformation 
turn out to be buggy.

> So obfuscation is just as easy in that language as in C++ or 
> Perls before version 6 despite the fact that its sysntax is 
> derived from Python.
>

The idea that a statically typed language with checked exceptions 
and an effect system (both features which didn't make it into 
0.9.0 though) is somehow less maintainable than Python with its 
dynamism everywhere is absurd.

> I can't say much about Scala and Groovy, but their syntax for 
> defining macros doesn't use as cryptic symbols as Nimrod. For 
> example I couldn't find out for first time what is nnk the nnk 
> prefix in the nnkInfix symbol.

Admittedly the macros API has been rushed out and the nnk 
prefixes are ugly. However there are addons that improve on the 
API. The core API will be improved too but it needs some 
transition path as unfortunately quite some code now depends on 
it. ;-)


More information about the Digitalmars-d mailing list