Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -1,8 +0,0 @@
// 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]()) }
}

View file

@ -0,0 +1,9 @@
val results = mutableListOf<() -> Int>()
var i = 0
while (i < 10) {
// Closures capture by reference, so reassignment is needed.
val j = i
results.add { j * j }
i++
}
println(results[3]()) // prints "9"

View file

@ -1,7 +1,7 @@
<?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
$funcs[] = function () use ($i) { return $i * $i; };
$funcs[] = fn() => $i * $i;
}
echo $funcs[3](), "\n"; // prints 9
?>

View file

@ -1,7 +1,7 @@
<?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
$funcs[] = create_function('', '$i = ' . var_export($i, true) . '; return $i * $i;');
$funcs[] = function () use ($i) { return $i * $i; };
}
echo $funcs[3](), "\n"; // prints 9
?>

View file

@ -0,0 +1,7 @@
<?php
$funcs = array();
for ($i = 0; $i < 10; $i++) {
$funcs[] = create_function('', '$i = ' . var_export($i, true) . '; return $i * $i;');
}
echo $funcs[3](), "\n"; // prints 9
?>

View file

@ -0,0 +1,9 @@
type
Tfuncs = integer-> () -> integer;
begin
var captor: Tfuncs := x -> () ->x * x;
var functions := Range(0, 10).Select(captor).ToArray;
println(functions);
println(functions[4]());
end.

View file

@ -0,0 +1,12 @@
fn new_counter() fn () int {
mut i := 0
return fn [mut i] () int {
i++
return i
}
}
count := new_counter()
println(count()) // 1
println(count()) // 2
println(count()) // 3