Can anyone explain why 0's and 1's are printed and not anything else? Thank you!
func makeFunction(name string) func() {
fmt.Println("00000")
return func() {
makeFunction2("abcef")
}
}
func makeFunction2(name string) func() {
fmt.Println("11111")
return func() {
makeFunction3("safsf")
}
}
func makeFunction3(name string) func() {
fmt.Println("33333")
return func() {
fmt.Printf("444444")
}
}
func main() {
f := makeFunction("hellooo")
f()
}
Can anyone explain why 0's and 1's are printed and not anything else? Thank you!
Let's follow the program flow:
main
starts.main
calls makeFunction
.makeFunction
prints 00000
, and returns an anonymous function.main
, we call the anonymous function returned by the previous call.makeFunction2
.makeFunction2
prints 11111
, and returns an anonymous function.main
returns.Because the return value is discarded after step 6 above, nothing else is printed.