Skip to content

Instantly share code, notes, and snippets.

@gregworley
Created September 22, 2010 15:28
Show Gist options
  • Save gregworley/591888 to your computer and use it in GitHub Desktop.
Save gregworley/591888 to your computer and use it in GitHub Desktop.
Function Literals are closures
package main
import "fmt"
func adder() (func(int) int) {
var x int
return func(delta int) int {
x += delta
return x
}
}
func main() {
var f = adder()
fmt.Print(f(1))
fmt.Print(f(1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment