But... I don't want my delegates to be lazy - breeding advice

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Aug 24 15:42:42 PDT 2006


BCS wrote:
> Andy Knowles wrote:
>> Walter Bright wrote:
>>
>>> Ok, I've thought about it a bit:
>>>
>>>     void foo(int x);    // same as before 0.165
>>>     void foo(int delegate() x)    // same as before 0.165
>>>
>>> and now:
>>>
>>>     void foo(lazy int x);
>>>
>>> In other words, 'lazy' is now a parameter storage class. This means 
>>> that:
>>>
>>>     void foo(int x);
>>>     void foo(lazy int x);
>>>
>>> cannot be distinguished based on overloading, but:
>>>
>>>     void foo(lazy int x);
>>>     void foo(int delegate() x);
>>>
>>> can be. The implicit conversion of a value to a delegate returning 
>>> that value would be removed. The conversion happens always (not 
>>> implicitly) if the parameter storage class is 'lazy'.
>>
>>
> 
> I like that a lot better.
> 
>> I think that is definitely a step in the right direction, and I think 
>> it will make people a lot more comfortable.
> 
> (I'm one of the above mentioned people)
> 
>>
>> Some questions:
>>
>> 1) While in void foo(lazy int x) will x be evaluated using x() or just 
>> x?  Either one could lead to confusion.
>>
> 
> I'd go for "x()", because
> 
> 1> it more closely reflects what is actually happening.
> 
> 2> it allows x to be used to refer to the delegate
> 

Indeed, "x()" is a better usage, however, if x is a delegate, then the 
"x" usage will still be allowed, due to the implicit call syntax (aka 
property syntax).



More information about the Digitalmars-d mailing list