RosettaCodeData/Task/Scope-Function-names-and-labels/Go/scope-function-names-and-labels-1.go
2015-02-20 00:35:01 -05:00

24 lines
560 B
Go

package main
import (
"fmt"
"runtime"
"ex"
)
func main() {
// func nested() { ... not allowed here
// this is okay, variable f declared and assigned a function literal.
f := func() {
// this mess prints the name of the function to show that it's an
// anonymous function defined in package main
pc, _, _, _ := runtime.Caller(0)
fmt.Println(runtime.FuncForPC(pc).Name(), "here!")
}
ex.X(f) // function value passed to exported function
// ex.x() non-exported function not visible here
}