Compare commits

...

3 Commits

Author SHA1 Message Date
Acaibrid 023527e229
Merge 24512d3625 into fa27be9e3f 2024-04-04 21:35:32 +08:00
chai2010 fa27be9e3f
Merge pull request #219 from gopl-zh/revert-213-patch-1
Revert "Update ch5-06.md"
2024-04-03 16:10:24 +08:00
chai2010 687fb92030
Revert "Update ch5-06.md" 2024-04-03 16:09:26 +08:00
1 changed files with 5 additions and 6 deletions

View File

@ -13,7 +13,7 @@ strings.Map(func(r rune) rune { return r + 1 }, "HAL-9000")
<u><i>gopl.io/ch5/squares</i></u>
```Go
// squares返回一个匿名函数。
// 该匿名函数每次被调用时都会返回下一个数的平方的函数
// 该匿名函数每次被调用时都会返回下一个数的平方
func squares() func() int {
var x int
return func() int {
@ -23,11 +23,10 @@ func squares() func() int {
}
func main() {
f := squares()
// () 函数调用符号
fmt.Println(f()()) // "1"
fmt.Println(f()()) // "4"
fmt.Println(f()()) // "9"
fmt.Println(f()()) // "16"
fmt.Println(f()) // "1"
fmt.Println(f()) // "4"
fmt.Println(f()) // "9"
fmt.Println(f()) // "16"
}
```