18 lines
427 B
Text
18 lines
427 B
Text
|
|
class Closures
|
||
|
|
{
|
||
|
|
Void main ()
|
||
|
|
{
|
||
|
|
// define a list of functions, which take no arguments and return an Int
|
||
|
|
|->Int|[] functions := [,]
|
||
|
|
|
||
|
|
// create and store a function which returns i*i for i in 0 to 10
|
||
|
|
(0..10).each |Int i|
|
||
|
|
{
|
||
|
|
functions.add (|->Int| { i*i })
|
||
|
|
}
|
||
|
|
|
||
|
|
// show result of calling function at index position 7
|
||
|
|
echo ("Function at index: " + 7 + " outputs " + functions[7].call)
|
||
|
|
}
|
||
|
|
}
|