Lazy eval

Pragma ericanderton at yahoo.removeme.com
Mon Aug 21 14:21:40 PDT 2006


Frank Benoit wrote:
> One more argument against the lazy-eval in the current form:
> 
> If you have no chance to figure out what the code does, without looking
> at docs or function signature....
> you will end up in writing 3 times more lines. Making each statements
> separated, to be sure to get them evaluated exactly once, without
> looking all that stuff up.
> 

You're right that the lazy eval, in it's fullest form, is a very 
stealthy (and arguably confusing) modification to the language.  I have 
some similar concerns myself.

However, Walter makes use of a slightly more obvious idiom in his 
discussion of this feature:

void log(char[] delegate() dg)
{
     if (logging)
	fwritefln(logfile, dg());
}

void foo(int i)
{
     log( { return "Entering foo() with i set to " ~ toString(i); });
}

IMO, this is probably the best way to go as it is perfectly obvious what 
is going on.  I like to think of it's counterpart (completely implicit 
conversion of expressions to delegates) as something a little more apt 
for generic programming - like being able to swap out a delegate for 
something else entirely.

-- 
- EricAnderton at yahoo



More information about the Digitalmars-d mailing list