CTFE thoughts & functional approach

cym13 via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 31 06:35:13 PST 2016


On Sunday, 31 January 2016 at 13:59:06 UTC, Robert M. Münch wrote:
> I like CTFE and the meta programming idea for languages like D.
>
> However, I'm wondering why most (everyone?) is trying to do 
> meta-programming using the same language as the one getting 
> compiled. IMO the use-cases a pretty different and doing CTFE, 
> code-generation etc. needs some other approach. If you look at 
> all the strange template syntax, strange hacks etc. it's all 
> far from being obvious.

I see things differently. First of all I don't see everyone trying
to do meta-programming with the same language. C++ for example has
a quite specific syntax between its arcane templates and the
preprocessor.

I see having the same language as a *huge* advantage. If a 
function
doesn't have side effects then it can be used at runtime or at
compile-time and integrated with your logic easily.

D's metaprogramming success is IMHO directly linked to it not 
having
a separate language for it, because it lowers the cost of learning
and using metaprogramming. It's saying "metaprogramming isn't
different from any other kind of programming, you can use the same
tools".

> Why not have a CTL (compile-time-language) that has access to 
> some compiler internals, that follows a more functional 
> concept? We are evaluating sequences of things to generate 
> code, include / exclude code etc.

Having access to some compiler internals is already what is done,
or I don't understand exactly what you mean by that.

> From my experience with the different approaches, functional 
> thinking is much better suited and simpler to use for CTFE 
> goals.

I think you should put some sort of example of how you'd want it,
because right now I don't understand. D has some nice functional
tools and they already show their strength at compile-time.

For example function purity is central to their CTFE-ability, 
using
template recursion instead of loops has often proved being a
winning strategy etc... Yes applying functionnal principles works
well at compile-time, but why should we need another language to 
do
that?



More information about the Digitalmars-d mailing list