https://golang.org/pkg/builtin/#append
If the initial slice ns has enough capacity, it will not be reallocated, but only resliced and modified in place. So, in your second example, ns1 and ns2 can end up being two slices that share the same underlying array. On Friday, July 15, 2016 at 7:28:32 PM UTC+2, Evan Digby wrote: > > I can't reproduce this in go playground (yet), but under what > circumstances would/could/should: > > nss := []namespace.Namespace{ > append(ns, g2message.NamespaceWin...), > append(ns, g2message.NamespaceSpend...), > } > > Act differently than: > > ns1 := append(ns, g2message.NamespaceWin...) > ns2 := append(ns, g2message.NamespaceSpend...) > > nss := []namespace.Namespace{ > ns1, > ns2, > } > > ns is a parameter on the function (actually, it's a parameter on the > function that generated the function that is being called, and ns is a > closure), and is currently: > > namespace.New("localhost") > > The definitions in the "namespace" and "g2message" packages are: > > type Namespace []string > > var NamespaceWin namespace.New("win") // New is making Namespace{"win"} > var NamespaceSpend namespace.New("spend") > > I would think under no circumstances; however, that's not my experience. > > Result of fmt.Println(nss) on the first example (expected): > > [[localhost win] [localhost spend]] > > Result of fmt.Println(nss) on the second example: > > [[localhost spend] [localhost spend]] > > > It's not running in a loop, separate goroutine, or anything. Those lines > are all that change between the two results. I'm at a loss. I will keep > trying to reproduce in go playground. > > > Thanks, > > > Evan > -- 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.