
This is a common operation: freevar := ... defer func() { println("I am deferred:", freevar) }() The function is thus an immediately applied closure. Only this form is currently supported, support for regular (fat) function pointers should be trivial to add but is not currently implemented as it wasn't necessary to get fmt to compile.
8 строки
176 Б
Text
8 строки
176 Б
Text
hello from function pointer: 5
|
|
deferring...
|
|
...run as defer 3
|
|
...run closure deferred: 4
|
|
...run as defer 1
|
|
bound method: foo
|
|
thing inside closure: foo
|
|
inside fp closure: foo 3
|