On Friday, October 14, 2016 at 12:14:34 AM UTC+8, Ian Lance Taylor wrote:
> > On Thursday, October 13, 2016 at 11:24:50 PM UTC+8, Jesper Louis
> > wrote:
> >> The rule is that a short variable declaration requires that at least
> >> non-blank variable is new (the specification even says so) Consider
> >> _, y := 4,5
> >> where one variable, y, is new. In
> >> _ := 6
> >> or
> >> _, _ := 5, 7
> >> this rule is violated, since there are no non-blank variables (and thus
> >> vacuously nothing new).
> >> I think the reason this is a rule is because it may detect some
> >> errors by forcing the programmer to write code in a certain style, but
> I may
> >> be wrong.
> > What spurious errors?
> The error of thinking that because you are using := you are getting a
> new variable.
> The handling of := is a bit tricky, perhaps too tricky. It used to
> always declare new variables, and give an error if there was already a
> variable of the same name in the same scope. But that was too painful
> to use with the err variable, because of the common use of
> n, err := F()
> So := was changed to permit reusing a variable if it already existed
> in the same scope with the same name and (inferred) type.
But the long variable declaration form only allows all variables are new
ones generally, except for the blank _ identifier.
Why not also make an exception for the blank _ identifier in the short form?
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.