mirror of
https://github.com/golang/go
synced 2024-11-26 17:26:56 -07:00
d528f52d87
Fixes #3241. R=golang-dev, r CC=golang-dev https://golang.org/cl/5835043
18 lines
288 B
Go
18 lines
288 B
Go
package main
|
|
|
|
// 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.
|
|
println(f(), f(), f(), f(), f())
|
|
}
|