golang-cheat-sheet
golang-cheat-sheet copied to clipboard
Update your golang_refcard.pdf, please
outer_var in the outer func wasn't changed because the anonymous inner function hadn't been called yet.
// Closures: don't mutate outer vars, instead redefine them!
func outer() (func() int, int) {
outer_var := 2 // NOTE outer_var is outside inner's scope
inner := func() int {
outer_var += 99 // attempt to mutate outer_var
return outer_var // => 101 (but outer_var is a newly redefined
// variable visible only inside inner)
}
return inner, outer_var // => 101, 2 (still!)
}
I saw you made updates on the README file, but some people may also read your pdf file.
Nony yet