Add Go sample

This commit is contained in:
Kiliman
2019-07-23 15:52:27 -04:00
committed by unknown
parent 9cef42b1fb
commit f7cafe55b3
+19
View File
@@ -0,0 +1,19 @@
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())
}