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 look at your main
:
f := makeFunction("hellooo")
makeFunction2("abcef")
, assigned to the identifier f
f()
which is equivalent to:
_ = f()
makeFunction3("safsf")
, discarded (you are not assigning the return value of f()
).makeFunction3
is never assigned to any identifier, and never called.