Metaprogramming in D : Some Real-world Examples

Nick Sabalausky a at a.a
Thu Nov 12 03:57:09 PST 2009


>"Bill Baxter" <wbaxter at gmail.com> wrote in message 
>news:mailman.337.1258023453.20261.digitalmars-d-announce at puremagic.com...
>Hi Nick,
>
>Thanks for the response.  More below.
>
>However, the unescape() function used in traceVal looks like it might
>be a useful CTFE example.  Some kind of compile-time string
>escaping/unescaping could definitely be a good example.

Heh, I tend to forget about that one. That's from the "semitwist.util.text" 
module, which I haven't worked with much in a long time, so there's probably 
a lot of WTFs spread through the module, and if you use something there as 
an example, you might need to clean it up a little. FWIW, that 
double-quote-string escaping/unescaping is built around ctfe_substitute 
which is in "semitwist.util.ctfe" (although Tango might have something 
similar by now).

>> [various]
>
>This is another one that C++ people would just throw macros at and
>wonder what the big deal is.

Ah, yea, good point. Of course, we'd probably all take D's metaprogramming 
over preprocessor macros anyday, but I can definitely see their point.

>> === Compile-time checking on types with non-identifier strings ===
>
>That is kinda neat, I suppose you could even extend that to make the
>list of valid tokens be a template parameter (either variadic, or
>separated by some delimiter in one big string that then gets broken up
>at runtime).  I guess you could pitch this as a baby step towards the
>full-fledged compile-time parser.  Step 0 recognize valid tokens.
>

Interesting idea, yea. Might not be much help for the lib as I currently 
have it though, since I'm just spitting out the static-style language 
definitions from a tool that takes in a grammar and generates D code. 
Certainly something to keep in mind for future expansion though.

>Thanks for writing all these up.

No prob! :)




More information about the Digitalmars-d-announce mailing list