Full closures for D
Craig Black
cblack at ara.com
Mon Nov 5 14:25:07 PST 2007
"Mikola Lysenko" <mclysenk at mtu.edu> wrote in message
news:fgns3v$1b13$1 at digitalmars.com...
> I'm excited. For the first time it is now possible to do futures in 7
> lines of code:
>
> T delegate() future(T)(lazy T expr)
> {
> T res;
> auto t = new Thread({res = expr();});
> t.start;
> return { t.wait; return res; }
> }
>
>
> Which could then be used as follows:
>
> auto hard_result = future( hard_expression );
>
> // Do stuff ...
>
> use_result(hard_result());
>
Very cool stuff! Did you test this code to see if it actually works?
A little off topic, but I was looking at your code and wondering if "lazy"
always means that the expression becomes a delegate? When a template is
used, the compiler could embed the expression directly rather than creating
a delegate. Since D is big on compile-time optimization, I was wondering if
it does this.
-Craig
More information about the Digitalmars-d
mailing list