Mariusz Gliwiński wrote:
Monday 27 December 2010 @ 17:18:17 Daniel Gibson:
Am 27.12.2010 17:01, schrieb Caligo:
On Mon, Dec 27, 2010 at 7:20 AM, Jonathan M Davis <jmdavisp...@gmx.com
<mailto:newshou...@digitalmars.com>> 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.
http://www.digitalmars.com/d/2.0/templates-revisited.html
Firstly,
I admit I'm still new in programming so treat me like that but...
On my peasant-like brain, if You can't store compilation-time variable, to
read it later... from other template, even module with normal language rules
but in compile time, it's not *fully* generative programming, is it? You can't
make many things without that.
You can store all compile-time results in local variables. (When a
couple of implementation bugs get fixed, you'll be able to store it in
heap-allocated variables as well).
So yes, with C++ style template metaprogramming, there's not so much you
can do. D CTFE metaprogramming is far more powerful, and it's also
simple to understand.
As I said, I'm new in programming so maybe that's why, but D was my ideal
language (so i could express everything i imagined). But this little thing
makes templates only small spice to what I've seen before, instead of big step
forward. I understand it might be hard to implement with clear rules of usage,
but I abstracted it out.
Ps. I want compile-time raytracer downloadable again, please :)
BTW -- I don't recommend doing anything complicated with template
metaprogramming. It becomes incomprehensible very quickly. CTFE, on the
other hand, scales very nicely.