D2 full closure?

Frank Benoit keinfarbton at googlemail.com
Sun Jul 13 09:13:12 PDT 2008


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.



More information about the Digitalmars-d mailing list