Go语言入门看这一篇就go了
package main
import "fmt"
// This function `intSeq` returns another function, which
// we define anonymously in the body of `intSeq`. The
// returned function _closes over_ the variable `i` to
// form a closure.
func intSeq() func() int {
i := 0
return func() int {
i += 1
return i
}
}
func main() {
// We call `intSeq`, assigning the result (a function)
// to `nextInt`. This function value captures its
// own `i` value, which will be updated each time
// we call `nextInt`.
nextInt := intSeq()
// See the effect of the closure by calling `nextInt`
// a few times.
fmt.Println(nextInt())
fmt.Println(nextInt())
fmt.Println(nextInt())
// To confirm that the state is unique to that
// particular function, create and test a new one.
newInts := intSeq()
fmt.Println(newInts())
}
- go语言快速入门:数据类型使用例(4)
- go语言快速入门:IPC之管道通信(8)
- go语言快速入门:Web应用的HelloWorld(11)
- go语言入门3 变量
- GO语言零基础入门资料整理
- Go语言入门(三)——map
- go 语言入门笔记
- Golang(Go 语言)入门学习-10-错误,数据读取与图像
- go语言快速入门:项目构建实践(21)
- go 语言入门
- Go语言入门8-方法method
- Go语言入门
- 入门学习go语言的网址
- go语言快速入门:简介(1)
- eclipse开发go语言入门案例
- 不一样的go语言之入门篇-Hello World
- 20170223--go语言入门
- Go语言入门2-流程控制语句
- Go语言基础入门--简介
- Go语言入门教程(一)Linux下安装Go