Created
October 28, 2013 08:22
-
-
Save zh4ngx/7193163 to your computer and use it in GitHub Desktop.
Quick demo/reminder of lexical closures (in Go)
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
// You can edit this code! | |
// Click here and start typing. | |
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello, 世界") | |
f := who() | |
g := who() | |
fmt.Println(f("DIck")) | |
fmt.Println(f("Wad")) | |
fmt.Println(f("twat")) | |
fmt.Println(g("fuck")) | |
fmt.Println(g("wad")) | |
} | |
func who() func(string) string { | |
var noun string | |
return func(name string) string { | |
noun += name | |
return noun | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment