3 ms·
I really wanted to learn something from this post, but it's mostly just hyperbole and whining. "It turns out that, in Go, you can't write a self-recursive anon
by pyrhho 15y ago
I really wanted to learn something from this post, but it's mostly just hyperbole and whining.
"It turns out that, in Go, you can't write a self-recursive
anonymous function - there's no way to make it refer to itself. Well, you can
do a dirty hack that's the "official work-around" (I'll let you google for the
bug report)."
To summarize this argument:
1. It is impossible to have a self-recursive anonymous function in Go.
2. Oh wait.. It is completely possible, but far too ugly to soil this blog post.
I looked up the temporary solution (http://code.google.com/p/go/issues/detail?id=226 http://code.google.com/p/go/issues/detail?id=226). It is this:
var recurse func()
recurse = func() {
recurse()
}
The proposed permanent solution is allowing recursive function definitions, because that is the proper solution instead of adding a magic self keyword like other languages do.
(tl;dr The author just doesn't like the fairly-simple work-around proposed while the language is still developing)
Edit: There definitely are far more important things in Go I dislike, and would change, however this blog post is essentially fluff.
- a_strange_guy 15y agoThis is what they want: func outer(a int) { func inner_helper(b int) { ... } } Pascal allowed nested functions 40 years ago...
- Peaker 15y agoWhen saying "nested functions" in 2011, people expect you to mean lexically scoped nested functions. Pascal's nested functions really just scoped the name of the function differently, but they were equivalent to a function definition on the outer-most level.