On 12/27/10 10:01 AM, Caligo wrote:
On Mon, Dec 27, 2010 at 7:20 AM, Jonathan M Davis <[email protected] <mailto:[email protected]>> wrote:On Monday 27 December 2010 04:41:37 spir wrote: > On Sun, 26 Dec 2010 12:06:04 -0800 > > Walter Bright <[email protected] <mailto:[email protected]>> wrote: > > 11. generative programming > > Does someone have a pointer to any kind of doc about this? (in D) Anything on templates, template mixins, and string mixins. All of them generate code. And some people have done some pretty crazy stuff with them (especially string mixins). - Jonathan M Davis So is it like template metaprogramming in C++? a small D example would be helpful. There doesn't seem to be anything about it in TDPL.
Look up the index for "mixin". Most, if not all, examples of string mixins are generative.
The canonical example I give is std.bitmanip.bitfields, see http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/bitmanip.d
As for CTFE, does this mean I could call 'writeln()' at compile time and have it print a message to stdout while compiling?
You can't because that's not pure. Incidentally you can use pragma(msg, "hello") as an alternate mechanism. Helped a lot while debugging std.bitmanip.bitfields :o).
Andrei
