String Mixins & Compile Time Evaluation

Bill Baxter wbaxter at gmail.com
Tue Nov 17 03:44:18 PST 2009


On Mon, Nov 16, 2009 at 8:25 PM, Travis Boucher
<boucher.travis at gmail.com> wrote:
> Don wrote:
>>
>> Travis Boucher wrote:
>>>
>>> I've been playing with string mixins, and they are very powerful.
>>>
>>> One thing I can't figure out is what exactly can and cannot be evaluated
>>> at compile time.
>>>
>>> For example:
>>>
>>> ----
>>> char[] myFunc1() {
>>>    return "int a = 1;";
>>> }
>>>
>>> char[] myFunc2() {
>>>    char[] myFunc3() {
>>>        return "int b = 2;";
>>>    }
>>>    return myFunc3();
>>> }
>>>
>>> void main() {
>>>    mixin(myFunc1());
>>>    mixin(myFunc2());
>>> }
>>> ----
>>>
>>> myFunc1() can be used as a string mixin.
>>> myFunc2() can't be.
>>
>> I think you're using an old version of DMD. It's been working since
>> DMD1.047. Please upgrade to the latest version, you'll find it a lot less
>> frustrating.
>> The bottom of "function.html" in the spec gives the rules.
>> Though it says nested functions aren't supported, but they are.
>
> Yeah, I am running 1.020 with gdc (freebsd default for gdc package).  I
> found a few work arounds, just trying to see what can be done.

Ohhhh, well yeh, Don's been smashing CTFE bugs like crazy lately.  I
think the version you're using doesn't even have the useful error
message fix that tells you what can't be CTFE'd.

So definitely upgrade before you try to do anything serious with CTFE.

--bb


More information about the Digitalmars-d-learn mailing list