bug in pragma?

JS js.mdnq at gmail.com
Thu Jul 4 17:44:21 PDT 2013


On Friday, 5 July 2013 at 00:06:30 UTC, Jonathan M Davis wrote:
> On Friday, July 05, 2013 01:51:56 JS wrote:
>> I think it's a logical flaw in D's CTFE system rather than some
>> innate reason why it doesn't work.
>
> The whole point of CTFE is to be able to call the same function 
> at compile
> time that you call at runtime. Having a function work at 
> compile time but not
> runtime would fundamentally break CTFE.
>
> And it's _way_ easier to reason about what code is going to do 
> if you
> understand the difference between stuff that's initialized at 
> compile time (like
> an enum) and stuff which is run at compile time. Trying to mix 
> the two would
> muddle things considerably.
>
> In any case, I would shocked if Don thought that CTFE should 
> work the way you
> think that it should work, and if you can't convince him, then 
> odds are,
> you're out of luck. I'm just trying to explain to you how the 
> language works
> and why what you're trying to do doesn't work.
>
> - Jonathan m Davis

Well, duh. Just because something works the way it works doesn't 
mean it's the right or best way.

Maybe a CTFE is suppose to have the exact same runtime and 
compile time behavior... it that is the case then we need 
something that is more powerful for compile time meta 
programming. At the moment all we have is basically CTFE.  I 
don't see why it is important to try and force a square peg into 
a round hole just because you have a square peg.

In any case, I seriously doubt that providing an "enum" with 
string concatenation at compile time would cause any difficulty 
and only make life much easier. If it breaks the CTFE common 
design between runtime and compile time then come up with a 
better way like having a compile time only meta functions that 
are meant to be used at compile time only for meta programming... 
it's not much of a leap from CTFE's... or allow CTFE's to be 
marked for compile time only which will allow enum string 
concatenation operations.

Just because something "can't" be done doesn't mean it can't...


More information about the Digitalmars-d mailing list