import ("fmt")var a intfunc main() {a := 1fmt.Println(a)}
AFAIK only reflection, but that's kind of ugly.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/9gK-oDHUvbw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-j
--
The best way to access it is not to shadow it in the first place :)
> Just make compiler smarter, so it wouldn't break in these cases?
That's shadowing. :)
It being a parameter wasn't the point. The same goes for any variable,
type, etc. declared anywhere. Breaking code because someone mentions
the same name at an outer scope would make everything rather fragile.
Importing a package is just an example of a common way to add a name
at the outermost scope, and for example "url" is a quite good variable
name as well. Not being able to use it would be sad.
On Friday, 15 April 2016 13:08:14 UTC+2, Ain wrote:
I don't think I have overlong functions, I usually get bitten with something likefoo := 42if bar {foo = doSomething()...}then after some refactoring doSomething returns another value, say errorfoo := 42if bar {foo, err := doSomething()if err != nil {...}...}note that I changed "=" to ":=" because the new var err, but now the outer foo isn't the one I assign value to.ain
Had shadowing not been permitted, you would have been forced to rename "foo", which would just make it clearer that it is a different variable.