Puzzle 8-10-08 (answer)

bearophile bearophileHUGS at lycos.com
Mon Aug 11 18:15:09 PDT 2008


Koroskin Denis:
>      return square!(a); // you can't instantiate a template
>      // with a variable (unless it is an alias, which is not a case)

Uhm... I think there can be ways to modify DMD to allow a better mixing of CT functions and templates.


> That's because compiler doesn't have to instantiate all those hundreds of  
> templates (and hold them in memory until exit).

Now the compile time is around 0.06 s, way less.
Such difference is very interesting. A functional language (even an interpreted one) can probably execute the code relative to those templates in way less than the original 1.8 seconds (it amounts to almost 4 billion clock ticks, it's a lot of computations!).
I presume DMD somehow contains an almost complete interpreter of D language (with GC) plus a functional language interpreter for the templates that can probably be improved, plus the compiler itself, it sounds like a lot of complexity/stuff :-)


> Note that now the  
> result is returned as a string due to a lack of compile time text output  
> (it will be output once per template/fuction instance).

Good idea, I'll remember it.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list