Skip to content

Instantly share code, notes, and snippets.

@dai
Created September 23, 2010 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dai/594343 to your computer and use it in GitHub Desktop.
Save dai/594343 to your computer and use it in GitHub Desktop.
package main
// fib returns a function that returns
// successive Fibonacci numbers.
// quoted by golamg.org
func fib() func() int {
a, b := 0,1
return func() int {
a, b = b, a+b
return b
}
}
func main() {
f := fib()
// Function calls are evaluated left-to-right.
println(f(), f(), f(), f())
}
@dai
Copy link
Author

dai commented Jul 10, 2012

こんなtinyな画面でgistedするほどのgeekじゃありません!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment