Function semantics
Closure capture
A closure can refer to surrounding variables even after the enclosing call returns. Closures created within the same activation may share those variables, not merely snapshots of their initial values. Example output: '1 2'.
Formal Syntax & Structure
go syntaxgo
func() int { return n }Working Example
Example Snippetgo
package main
import "fmt"
func counter() func() int { n := 0; return func() int { n++; return n } }func main() { next := counter() fmt.Println(next(), next())}