Would there be interest in a SERIOUS compile-time regex parser?
Bill Baxter
dnewsgroup at billbaxter.com
Tue Oct 17 23:55:28 PDT 2006
Reiner Pope wrote:
> Knud Sørensen wrote:
>> On Tue, 17 Oct 2006 12:23:33 -0700, Walter Bright wrote:
>>
>>> Don Clugston wrote:
> Three short answers:
>
> 1. This would be easy to do (ie it is only heavy syntax sugar) for a
> limited subset of the language (this subset would exclude reference
> semantics).
>
> 2. It would be possible to do for almost the entire language, but would
> require a real interpreter at compile time, which means a fair bit more
> work (but still possible and very appealing).
>
> 3. Neither of these two mechanisms would be enough to do away with the
> primary motivation for templates -- parameterised types. However, they
> would remove the need for a Turing-complete template system.
...
> Both of these systems would incorporate a way of saying, 'evaluate this
> at compile time', even if it were just as simple as declaring the
> variable const, using it as a template parameter or in a static if:
>
> version (good) { const int N = 80; }
> else { const int N = 16 }
> const foo = sqrt(N); // foo is 4
> static if (sqrt(foo) > 3) // that expression must be a compile-time
> constant
> alias ubyte MyByte;
> else
> alias byte MyByte;
> List!(foo, MyByte) myList;
>
> The main motivations for this are, (in decreasing order of importance):
> - ability to use runtime functions for static if and template
> parameters (where static if is important because of
> - early catching of errors (eg incorrect regexes)
> - efficiency (eg not having to compile the regex at runtime; also,
> having cheap reflection at compile time)
This is exactly what I've been hoping someone would invent too. It
seems like the next logical step in template metaprogramming. I think
Walter's hip to the idea too. Soon after the last big discussion about
metaprogramming stuff and making it more like a true compile-time
programming language, "static if" appeared. I think that was something
that Walter realized was "low-hanging fruit", which could quickly be
implemented today and have a big impact now without waiting around till
D 3.0.
So, I think it's vaguely on the D roadmap somewhere, it's just a huge
undertaking and will take time.
--bb
More information about the Digitalmars-d
mailing list