Skip to content

Instantly share code, notes, and snippets.

@zh4ngx
Created October 28, 2013 08:22
Show Gist options
  • Save zh4ngx/7193163 to your computer and use it in GitHub Desktop.
Save zh4ngx/7193163 to your computer and use it in GitHub Desktop.
Quick demo/reminder of lexical closures (in Go)
// 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