New syntax for string mixins
VladD2
vc at rsdn.ru
Fri Dec 17 22:10:34 PST 2010
Don Wrote:
> > You missed: pattern matching,
>
> Yes, you've got me there. I've assumed that pattern matching, while a
> major feature, is not fundamental to the Nemerle macro-system, but I may
> be mistaken.
>
> One obvious difference which *is* fundamental is that Nemerle macros
> allow new syntax.
>
> Am I correct in thinking that Nemerle always requires complete ASTs?
> That is, given a name "x", can you access variables "x1", "x2", "x3" ?
>
> > quasi-quotation,
>
> No, that's present in D. It's the primary reason I say that the
> differences are mostly syntactic, since I see this as THE fundamental
> feature. You need to be able to reenter the macro system after you have
> left it. Once you can do that, you can do pretty much anything.
You not understand... pattern matching and quasi-quotation tightly bound. The quasi-quotation produce instances of Algebraic Data Type (AlgTD) which can be decomposed (and matched) by pattern matching (PM). We use PM to "read" code of a project.
For example, see C# grammar:
http://code.google.com/p/nemerle/source/browse/nemerle/trunk/snippets/csharp-parser/CSharpParser/Parser.n?r=9436
which made by PegGrammar macro:
http://code.google.com/p/nemerle/source/browse/nemerle/trunk/snippets/peg-parser/Nemerle.Peg.Macros?r=9436
Or see our foreach macro:
http://code.google.com/p/nemerle/source/browse/nemerle/trunk/macros/core.n?r=9436#508
> > running of fully functional Nemerle
> > code in compile time,
>
> Yes, but that's a different issue. In D, running code at compile time is
> regarded as an aspect of constant-folding, and is not restricted to
> macros.
The constant-folding is too limited solution.
The power of of macros, including the ability to use are any libraries and any data sources.
And ... you use enterpretation... slow way.
> > access to compiler API in macros
>
> In practice, has to be a library, right? Otherwise the compiler
> internals would be exposed? (This is an issue we're struggling with).
Yes. The Nemerle compiler is library. :)
Unfortunately Nemerle API is not pretty clear. But I believe it's a right way.
P.S.
Sorry for my (Russian) English. :)
More information about the Digitalmars-d
mailing list