No household is perfect

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Dec 4 08:22:57 PST 2013


On 12/4/13 7:06 AM, H. S. Teoh wrote:
> 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.

Yah, my thoughts exactly. Looks like we're in a sweet spot there.

Andrei



More information about the Digitalmars-d mailing list