box-o-sand/gotime/gotour-artifacts/exercise-fibonacci-closure/main.go
Dan Buch 44999623da Collapsing tree into more sane Go project layout
since I was in here looking at something unrelated...
2012-12-13 18:12:43 -05:00

24 lines
330 B
Go

package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
prev := 0
cur := 1
return func() int {
old_cur := cur
cur = prev + cur
prev = old_cur
return cur
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}