No household is perfect
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Dec 4 07:06:06 PST 2013
On Wed, Dec 04, 2013 at 04:23:59AM +0100, bearophile wrote:
> Joshua Niehus:
>
> >This would make for a good blog post/wiki article. Does one
> >already exist?
>
> If you have a AST macros like in Julia language, I think you can
> write something like:
>
> @setExpr(a ∪ (b ∩ c));
>
> The main difference is that the compiler gives you a tree in the
> macro to work on, instead of a string to parse and munge.
[...]
The problem with having the compiler parse it is that it has to be in a
syntax understood by the compiler. If your DSL needs a radically
different syntax, it won't work (e.g., regex: how is the compiler to
know '+' is a postfix operator instead of an infix one?).
By having a compile-time string as input, you have maximum flexibility.
It's essentially writing a mini-compiler embedded in D, because it runs
in CTFE.
T
--
You are only young once, but you can stay immature indefinitely. -- azephrahel
More information about the Digitalmars-d
mailing list