I dun a DIP, possibly the best DIP ever
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Apr 27 22:40:20 UTC 2020
On Mon, Apr 27, 2020 at 03:15:53PM -0700, Walter Bright via Digitalmars-d wrote:
[...]
> Actually, you can write expression templates in D (I've done it as a
> demo). But it is a bit more limited in D because D doesn't allow
> separate overloads for < <= > >=, for example.
>
> A far as Boost Spirit goes, more than one person has made a D parser
> generator using mixins that is far better.
Operator overload abuse of the kind Boost Spirit does makes me cringe.
Not only it uglifies the code, it's also unnatural to write because the
abused built-in operators don't even look like how traditional grammar
operators would be written, making it unnatural to read in addition to
be a pain to write. (And don't even talk about the nastiness of
debugging that mess, with reams of errors each of which occupies
multiple pages of unreadably-long nested template symbols.)
D's recommended approach of using a string mixin or string argument to a
CTFE generator function is *so* much better. You can write normal code
that generates a parser instead of deeply-nested recursive templates,
and you can use natural notation instead of contorting everything to fit
into built-in operators that have been shoehorned into purposes utterly
alien to their original design.
On a larger-picture note, I think that in the long term the way of
progress lies with first-class types manipulated by CTFE functions that
treats them like "runtime" values, that Stefan has been proposing. While
templates are Turing-complete, and in theory can express all possible
compile-time manipulations you might want to do, actually doing so is
like trying to write a GUI application in lambda calculus. It's
*possible* but extremely tedious, error-prone, and just overall painful
to write, maintain, and debug. (Not to mention consumes gobs of
resources at compile-time and causing insane compiler slowdowns.) Being
able to manipulate types and arrays of types (tuples, and the rest of
its ilk) will bring D meta-programming into a whole new level that will
outpace every other language capable of meta-programming that I know of.
(Maybe besides Lisp macros. :P) Couple this with newCTFE, and I think
we have a killer combo.
T
--
Never ascribe to malice that which is adequately explained by incompetence. -- Napoleon Bonaparte
More information about the Digitalmars-d
mailing list