直接看代码:
package main
import "fmt"
func fibonacci(s1,s2 int) func() int {
fmt.Println("start with:",s1,s2)
left := s1
right := s2
return func() int {
nest := left + right
left = right
right = nest
return nest
}
}
func main() {
f := fibonacci(0,1)
for i := 0; i < 10; i++ { fmt.Println(f()) }}