D1 -> D2

Fawzi Mohamed fawzi at gmx.ch
Thu Nov 18 23:39:49 PST 2010


On 19-nov-10, at 08:08, Walter Bright wrote:

> Fawzi Mohamed wrote:
>> From the discussion it seems that defining something like:
>> version(D_Version2){
mixin(`
>>    template Const(T){
>>        alias const(T) Const;
>>    }
>>    template Immutable(T){
>>        alias immutable(T) Immutable;
>>    }
>>    immutable(T) Idup(T)(T val){
>>        return val.idup;
>>    }
>>    alias const(char)[] cstring;
`);
>> } else {
>>    template Const(T){
>>        alias T Const;
>>    }
>>    template Immutable(T){
>>        alias T Immutable;
>>    }
>>    T Idup(T)(T val){
>>        return val.dup;
>>    }
>>    alias char[] string;
>>    alias char[] cstring;
>> }
>> could help a lot
>> later one can simply replace Const! with const and Immutable! with  
>> immutable, Idup replacement is more complicated, but doable
>
> The problem with this approach is it requires the D1 compiler to be  
> able to parse D2 syntax, including recognizing all of D2's keywords.

yes you are right, I meant to put a mixin ther but then I forgot it.

>> What is not so clear is how to cope with scope, because I have lot  
>> of delegates around that will need it.
>> For it a preprocessing step might really be the best thing, or  
>> someone knows a smart way to cope with that?
>
> Not sure what the issue is.

I don't find a valid D1 expression to put in place of scope, or to  
somehow hide it, i.e. how do you write something like
module t;

void f(scope void delegate() action){
     action();
}

void main(){
     f(scope delegate(){
         printf("bla\n");
     });
}

so that it is valid D1 and D2?



More information about the Digitalmars-d mailing list