package main
import "fmt"
// 返回一个“返回int的函数”
func fibonacci() func() int {
var last = 0
var cur = 1
var count = 0
return func() int {
return func() int {
switch count {
case 0:
count += 1
return 0
case 1:
count += 1
return 1
default:
last, cur = cur, last + cur
count += 1
return cur
}
}()
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}