April 28, 2007
Walter Bright Wrote:

> I keep racking my brain trying to come up with a short, pithy example of CTFE that uses AAs or struct literals. It should be just a few lines, and make it clear why CTFE is a great thing. I want to use it in presentations.
> 
> Any ideas?

How about one that, given a function pointer/delegate and the name of a Java package, wraps it for the JNI with the correct naming scheme and C calling convention.
April 28, 2007

Robert Fraser wrote:
> Walter Bright Wrote:
> 
>> I keep racking my brain trying to come up with a short, pithy example of CTFE that uses AAs or struct literals. It should be just a few lines, and make it clear why CTFE is a great thing. I want to use it in presentations.
>>
>> Any ideas?
> 
> How about one that, given a function pointer/delegate and the name of a Java package, wraps it for the JNI with the correct naming scheme and C calling convention.

I don't think you could do that with CTFE.  Unless I'm missing something, CTFE can only generate values, not code or types.

Well, not unless you involve the mixin keyword, but there doesn't seem to be anything you can do with that that couldn't be done with templates.

I think that, at this stage, CTFE doesn't really *have* one awesome example you can point to and say "is it not nifty?"  The "problem" is that CTFE seems to be a nicer way of generating source code strings and other values at compile time.

Maybe you could show CTFE being used for pre-computing a table of sine and cosine values, or show it being used to generate a source string as compared to an equivalent template version.

That, or you could use that brainf*ck compiler someone wrote using CTFE.
 At least, I think it was CTFE...

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/