Lazy evaluation
Stewart Gordon
smjg_1998 at yahoo.com
Fri Jun 29 04:24:18 PDT 2007
"OF" <nospam at nospammington.com> wrote in message
news:f5u09a$1mmq$1 at digitalmars.com...
> Hey. I've been writing a bit on a "true" lazy evaluation (i.e.
> not evaluated until value is requested, but only evaluated once).
> A simple example of this can be achieved using a delegate, like so:
<snip>
> Which would work fine with Lazy!(int)( { return someExpr; } ), but
> it would be nice to be able to just use Lazy!(int)( someExpr ).
> However, it seems this can only be achieved using lazy function
> arguments, but problem is, if I use lazy function arguments, I
> can't really save it for later and do anything worthwhile with it.
<snip>
Actually you can take advantage of the fact that lazy expressions can be
used for variadic delegate parameters.
this(T delegate()[1] exp...)
{
mExp = exp;
}
enables you to use
Lazy!(int)(someExpr)
I used this to make an Unlambda to D compiler, and it even made it
straightforward to implement the d builtin (which David Madore thought would
be very hard to compile). Now the only thing that's left is getting c
working properly.
Stewart.
More information about the Digitalmars-d
mailing list