repost: semantics of the keyword lazy
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Thu Oct 12 00:41:15 PDT 2006
Karen Lanrap wrote:
> I have posted the following in the learn-group without any answers:
>
>
> From the documentation:
>
> Lazy arguments are evaluated not when the function is called, but
> when the parameter is evaluated within the function.
>
>
> First to note, that this is a circular definition without any fixed
> point to start from:
> a lazy argument is evaluated, when it is evaluated :-(
This is not a circular definition.
import std.stdio;
void func(lazy int x) // x is a parameter
{
writefln(x()); //parameter evaluated here
writefln(x()); //and once again here
}
void main()
{
int x;
func({return x++;}());
//{return x++;}() is and argument and it is not called here
}
The thing is: argument and parameter are not one and the same and that
makes the definition not circular.
More information about the Digitalmars-d
mailing list