another idea for compile time functions

Hasan Aljudy hasan.aljudy at gmail.com
Fri Feb 9 00:09:56 PST 2007



janderson wrote:
> Kevin Bealer wrote:
>> Let's say I have these two functions:
>>
>> char[] foo(char[] a, char[] b) metaok;
>> char[] bar(char[] a, char[] b, char[] c) metaok;
>>
>> The metaok keyword means "this can be run at compile time."
>>
>> Suppose further that bar(a,b,c) calls foo(a,b) as a base case, and 
>> that both are generated via the "meta" mechanism.  No mutual recursion 
>> or anything though.
>>
>> What order do you compile them in?  Obviously, foo then bar -- bar 
>> needs foo to be runable at compile time.
>>
> 
>> Kevin
> 
> I think that is a good case for labeling which functions are 
> compile-time safe, although I think it solveable.
> 
> Here's another case for problems:
> 
> void
> 
> mixin
> {
> "char [] foo1" ~ foo3 ~ "{...}"
> };
> 
> void
> 
> mixin
> {
> "foo2" ~ foo1()  ~ "{...}"
> };

That one might work by luck, but that's not the intended usage of 
compile-time execution so I think it'd be safe to define that as an 
error; i.e. specify that mixed-in code is not compile-time executable.

> 
> 
> How is the compiler going to figure that one out.  Parhaps there should 
> be some more rules to help with these cases?  Maybe its possible to 
> compile it?  Maybe something to do with namespacing?  I'm not sure.  I 
> think would be possible.
> 
> I think you shouldn't be able to access functions a compile time defined 
> in a mixin.  But I'm sure there are many other cases like this to figure 
> out.
> 
> -Joel



More information about the Digitalmars-d mailing list