September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Closures-Value-capture/00META.yaml
Normal file
1
Task/Closures-Value-capture/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import system'routines.
|
||||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
public program =
|
||||
[
|
||||
var functions := Array new(10); populate(:i)<int>( [ ^ i * i ] ).
|
||||
public program()
|
||||
{
|
||||
var functions := Array.allocate(10).populate:(int i => (^ i * i) );
|
||||
|
||||
functions forEach(:func) [ console writeLine(func()). ].
|
||||
].
|
||||
functions.forEach:(func) { console.printLine(func()) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
use Collection.Generic;
|
||||
|
||||
class Capture {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
funcs := Vector->New()<FuncHolder<IntHolder> >;
|
||||
|
||||
for(i := 0; i < 10; i += 1;) {
|
||||
funcs->AddBack(FuncHolder->New(\() ~ IntHolder : () => i * i)<IntHolder>);
|
||||
};
|
||||
|
||||
each(i : funcs) {
|
||||
func := funcs->Get(i)->Get()<IntHolder>;
|
||||
func()->Get()->PrintLine();
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue