Compile Time Fun Time
Paul Backus
snarwin at gmail.com
Mon Feb 25 20:16:41 UTC 2019
On Monday, 25 February 2019 at 06:51:20 UTC, Yevano wrote:
> I am writing a domain specific language of sorts in D for the
> lambda calculus. One of my requirements is that I should be
> able to generate expressions like this:
>
> new Abstraction(v1, M)
>
> like this:
>
> L!(x => M)
A word of caution: this kind of thing looks cute, but
fundamentally, you are using D's lambda syntax in a way it was
never intended to be used. The more you try to build on top of
this, the more you will find yourself fighting the language, and
the more you will be forced to resort to ugly, brittle
workarounds to make your DSL function.
A much better approach is to write your DSL inside string
literals, and parse it into proper data structures using CTFE.
For example:
L!"x.M"
...would be equivalent to something like:
Abstraction(Variable("x"), M)
More information about the Digitalmars-d-learn
mailing list