I extracted the confusing part alone, when appending to an array, the items are different than the resultant array into a separate go program.
The Playground URL is: https://play.golang.org/p/BJM0H_rYNdb If someone can explain the output I would be thankful. It feels like a bug to me, but I am sure that I am only misunderstanding and it may not be a bug. Thanks. 2018-05-23 11:45 GMT+05:30 Sankar P <sankar.curios...@gmail.com>: > Use an array instead of a slice. An array has a fixed size and can be used >> as a key to a map >> >> https://play.golang.org/p/xxxmrwpx08A >> > > This seem to not work. The arr is returning only duplicate elements in > your playground url. > > For example: > > var arr [][]int > for mem := range m { > fmt.Println("Appending: ", mem[:]) > arr = append(arr, mem[:]) > } > fmt.Println("Final arr is:", arr) > > the output is: > > Appending: [-1 0 1] > Appending: [-1 -1 2] > Final arr is: [[-1 -1 2] [-1 -1 2]] > > I am not really able to understand why the above code works so. The > "Appending" and the "Final arr" statements have different values. > > -- > Sankar P > http://psankar.blogspot.com > -- Sankar P http://psankar.blogspot.com -- 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.