This commit is contained in:
a.pivkin 2026-01-04 19:16:49 +03:00
parent 204c4c783f
commit 8aceabf0f1

View File

@ -2,18 +2,19 @@ package main
import "fmt"
func square() func () int {
var x int
return func() int {
x++
return x*x
}
type Point struct {
x int
}
func (p *Point) Inc() {
p.x++
}
func main() {
f := square()
fmt.Println(f())
fmt.Println(f())
fmt.Println(f())
fmt.Println(f())
fmt.Println(f())
points := []*Point{{1},{2},{3}}
for _,p := range points {
p.Inc()
}
fmt.Println(points[0].x)
}