Lazy evaluation of function arguments in D

deadalnix deadalnix at gmail.com
Sun May 20 08:47:53 PDT 2012


Le 20/05/2012 16:17, Timon Gehr a écrit :
> On 05/20/2012 04:09 PM, deadalnix wrote:
>> Le 20/05/2012 01:03, Walter Bright a écrit :
>>> http://www.reddit.com/r/programming/comments/tui75/lazy_evaluation_of_function_arguments_in_d/
>>>
>>>
>>>
>>
>> This feature break pure/@safe/nothrow .
>>
>
> It does not break them.
>
> lazy currently makes it impossible to have some guarantees that might be
> desirable to have inside the function with the lazy parameter, but the
> call site has all the information needed in order to establish them again.
>

How would you create a nothrow function with a lazy parameter ?

This will depend both on the callee and the caller, for instance :

nothrow void foo(lazy int i) {
     try {
         // Do something with i.
     } catch(Exception e) {}
}

This function is nothrow even if the parameter isn't. Without the try 
catch, the function can be nothrow depending on what is passed as argument.

The article state that the whole point is : « The only trouble is that 
few are going to want to wrap expressions with { return exp; }. »

If so, this isn't complicated, just do some rewrite magic on the 
expression if it is given and expression where a delegate is expected.

lazy prevent expressing the attribute needed. And extending lazy would 
ends up to the point where you remove the delegate keyword and replace 
it with lazy.


More information about the Digitalmars-d mailing list