Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -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.
|
||||
14
Task/Closures-Value-capture/Go/closures-value-capture-2.go
Normal file
14
Task/Closures-Value-capture/Go/closures-value-capture-2.go
Normal 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]())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue