Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package ex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// X is exported.
|
||||
func X(x func()) {
|
||||
pc, _, _, _ := runtime.Caller(0)
|
||||
fmt.Println(runtime.FuncForPC(pc).Name(), "calling argument x...")
|
||||
x()
|
||||
}
|
||||
|
||||
func x() { // not exported, x not upper case.
|
||||
panic("top level x")
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// labels loop and y both in scope of main
|
||||
loop:
|
||||
for false {
|
||||
continue loop
|
||||
}
|
||||
goto y
|
||||
y:
|
||||
y := 0 // variable namespace is separate from label namespace
|
||||
|
||||
func() {
|
||||
// goto loop ...loop not visible from this literal
|
||||
|
||||
// label y in outer scope not visible so it's okay to define a label y
|
||||
// here too.
|
||||
y:
|
||||
for {
|
||||
break y
|
||||
}
|
||||
y++ // regular lexical scoping applies to variables.
|
||||
}()
|
||||
fmt.Println(y)
|
||||
}
|
||||
|
||||
// end: // labels not allowed outside function blocks
|
||||
Loading…
Add table
Add a link
Reference in a new issue