mirror of
https://github.com/golang/go
synced 2024-11-02 13:42:29 +00:00
a5e10edc34
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6849105
19 lines
306 B
Go
19 lines
306 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
// fib returns a function that returns
|
|
// successive Fibonacci numbers.
|
|
func fib() func() int {
|
|
a, b := 0, 1
|
|
return func() int {
|
|
a, b = b, a+b
|
|
return a
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
f := fib()
|
|
// Function calls are evaluated left-to-right.
|
|
fmt.Println(f(), f(), f(), f(), f())
|
|
}
|