From my reading of the spec:
A short variable declaration ... is a shorthand for a regular variable declaration with initializer expressions but no types...
I would have thought the two were identical:
var f func()
f = func() {
...
}
and
f := func() {
...
}
But it seems like they're not. I was trying to wrap a self-recursive function inside of an outer function, but this works:
func myOuter() {
var f func()
f = func() {
f()
}
f()
}
But this doesn't, saying undefined: f
in the inner function.
func myOuter() {
f := func() {
f()
}
f()
}
So what is the difference? Is there any way to write this with the short-form declaration or I do I have to write it out long-hand?