Lazy evaluation of function arguments in D

Timon Gehr timon.gehr at gmx.ch
Mon May 21 02:35:30 PDT 2012


On 05/21/2012 11:07 AM, renoX wrote:
> On Sunday, 20 May 2012 at 00:26:14 UTC, Mehrdad wrote:
>> http://www.reddit.com/r/programming/comments/tui75/lazy_evaluation_of_function_arguments_in_d/c4pwvyp
>>
>>
>> +1 ^
>
> +1 too:
>
> 'f(x++)' what's the value of x after executing this function call?
>
> If f is a function with a normal argument, the new value is x + 1, if f
> is a function with a lazy argument, the new value can be anything
> (depends on how many time the expression is evaluated).
>

int x;

void f(int){x=anything;}

void main(){ f(x++); }


> So the lazy keyword hurts maintainability:
> you need an IDE which color differently the callsite to be usable, really ugly..
>

Have you actually encountered this problem in practice?

> How about improving 'f({ return x ++ })' to either f({^x++})' (^ is
> return in Smalltalk) or 'f({x++})'?
>

f(()=>x++) is already short enough.


More information about the Digitalmars-d mailing list