Revised RFC on range design for D2
Michel Fortin
michel.fortin at michelf.com
Fri Oct 3 04:57:56 PDT 2008
On 2008-10-03 06:27:24 -0400, Fawzi Mohamed <fmohamed at mac.com> said:
> So actually automatically evaluating the delegate would actually fix
> this particular problem (but would indeed introduce many other
> problems, like how to then get the delegate).
Hum... it could work a little like references (&) in C++. Basically, if
you assign a lazy value to another lazy value, it just copy the
delegate. Obviously, you'd need to allow "lazy" as a type modifier
everywhere, in the same sense as "ref" could (will?) be made a type
modifier acceptable everywhere.
void func(lazy int x)
{
lazy int y = x; // assigns x delegate to y.
y; // calls y delegate, which is the same as x.
x; // calls x delegate.
}
We could even extend the concept to create "lazy values", which could
work as getters for properties, and disallow parenthesis for them:
lazy int func { return 1; }
lazy int delegate() deleg { return &func; }
int i = func; // calls func.
int j = func(); // error, func is lazy and cannot be called with parenthesis.
int k = deleg(); // calls deleg(), then evaluate the returned delegate.
lazy int x = func; // assigns &func to x.
lazy int delegate() y = deleg; // assigns &deleg to y.
lazy int z = deleg(); // implicitly creates a delegate for calling
deleg() lazily.
Doesn't this generalize well?
I'm just not sure how to extend this to a syntax for setters though. Ideas?
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d-announce
mailing list