On Fri, Nov 18, 2016 at 7:02 AM, Terry McKenna <terry.mcke...@gmail.com> wrote: > > I am reading "The Go Programming Language": Donovan, Kernighan (pg.31): > > "One subtle but important point: a short variable declaration does not > necessarily declare all the variables on the its left-hand side. If some of > them were already declared in the same lexical block then then the short > variable declaration acts like an assignment to those variables." > > I get that. > > "In the code below, the first statement declares both in and err. The second > declares out but only assigns a value to the existing err variable: > > in, err := os.Open(infile) > // ... > out, err := os.Create(outfile) > > A short variable declaration must declare at least one new variable ...." > > My question is, the second declaration (out, err := os.Create(outfile)), is > declaring a new var so why is the value from "os.Create(outfile)" not > assigned to out? I understand that err is updated but again, why is no value > assigned to the variable out?
It does assign a value to the variable out. I think the book is trying to stress that it declares out but does not declare err. I agree that the sentence seems to imply that it does not assign a value to out, but in fact it does both declare out and assign a value to it. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.