Closures/Value capture: Difference between revisions
Added Kotlin
(Added FreeBASIC) |
(Added Kotlin) |
||
Line 1,043:
julia> funcs[7]()
49
</pre>
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
fun main(args: Array<String>) {
// create an array of 10 anonymous functions which return the square of their index
val funcs = Array(10){ fun(): Int = it * it }
// call all but the last
(0 .. 8).forEach { println(funcs[it]()) }
}</lang>
{{out}}
<pre>
0
1
4
9
16
25
36
49
64
</pre>
|