0. Getting Started
0.0 about slice
slicesare like reference to arrays (underlying array), they don’t store any data.slicesare dynamically-sized, they have a “special” way to extend theirs’ capacity- when cap(s) < 1024: it enlarges to 2*cap(s)
- when cap(s) > 1024: it enlarges by 25%, and adjust to the min value that
Sys.PtrSizeneeds. - reference: https://blog.csdn.net/u011622226/article/details/114757305
0.1 about closures
A
closureis a function value that references variables from outside its body.- A
closureis bound to its own variable, diffenert initialization of the closure is different. ```go package main
import “fmt”
func fibonacci() func() int{ pre, now := 0, 1 return func() int { now = pre + now pre = now - pre return pre } } func main() { f := fibonacci() for i := 0; i < 10; i ++ { fmt.Println(f()) } } ```
