Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,26 @@
program testthis;
{$mode objfpc}{$modeswitch functionreferences}{$modeswitch anonymousfunctions}
type
TFuncIntResult = reference to function: Integer;
// use function that returns anonymous method to avoid capturing the loop variable
function CreateFunc(i: Integer): TFuncIntResult;
begin
Result :=
function: Integer
begin
Result := i * i;
end;
end;
var
Funcs: array[0..9] of TFuncIntResult;
i: integer;
begin
// create 10 anonymous functions
for i := Low(Funcs) to High(Funcs) do
Funcs[i] := CreateFunc(i);
// call all 10 functions
for i := Low(Funcs) to High(Funcs) do
Writeln(Funcs[i]());
end.

View file

@ -0,0 +1,14 @@
package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
}