返回函数的匿名函数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package main
import "fmt"
type Point struct{ X, Y float64 }
func main() {
f := func(p Point) func () int {
var x int
return func () int {
x++
return x * x
}
}
p := Point{1, 2}
g:=f(p)
fmt.Println("result:",g())
fmt.Println("result:",g())
}
result: 1 result: 4
由于 go get code.google.com/p/go-tour/gotour
报错:
# cd .; hg clone -U https://code.google.com/p/go-tour /usr/home/huaying/go/src/pkg/code.google.com/p/go-tour
abort: error: EOF occurred in violation of protocol
package code.google.com/p/go-tour/gotour: exit status 255