D2 full closure?
Jason House
jason.james.house at gmail.com
Sun Jul 13 16:22:48 PDT 2008
Frank Benoit Wrote:
> With DMD 2.015:
>
> alias void delegate() Runner;
> void main(){
> Runner[] runner;
> for( int i = 0; i < 3; i++ ){
> const int ci = i;
> runners ~= delegate(){
> writefln( "run with ci=%d", ci );
> }
> }
> foreach( runner; runners ){
> runner();
> }
> }
>
>
> Output:
> run with ci=2
> run with ci=2
> run with ci=2
>
> Is this output expected?
> From the technical point yes, because i know how it is implemented.
> But is this expected in the sense of "Full closure"?
>
> In Java, if ci would be "final" and the delegate an anonymous class,
> the output would be 0,1,2.
I could have sworn there was a bug report to make this work like you want. Another alternative is to use bind.
More information about the Digitalmars-d
mailing list