Created
May 27, 2014 08:21
-
-
Save shockalotti/5024be3c2a05d49f20a9 to your computer and use it in GitHub Desktop.
Go Golang - Closures have access to other local variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
x := 0 | |
increment := func() int { | |
x++ | |
return x | |
} | |
fmt.Println(increment()) | |
fmt.Println(increment()) | |
fmt.Println(increment()) | |
fmt.Println(increment()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment