Hi guys, I came across some code that surprised me, but I could not figured out why it behave like this,
s := make([][]int, 0) a1 := [3]int{1, 2, 3} a2 := [3]int{4, 5, 6} s = append(s, a1[:]) s = append(s, a2[:]) fmt.Println(s) mp := make(map[[3]int]bool) mp[[3]int{1, 2, 3}] = true mp[[3]int{4, 5, 6}] = true mp[[3]int{7, 8, 9}] = true res := make([][]int, 0) for k := range mp { fmt.Printf("key is %+v\n", k[:]) res = append(res, k[:]) fmt.Printf("after append: %+v\n", res) } or on playground <https://play.golang.org/p/LicUSbr0g1a> the output is: [[1 2 3] [4 5 6]] // this is as expected key is [1 2 3] after append: [[1 2 3]] key is [4 5 6] after append: [[4 5 6] [4 5 6]] // Why it get this not [[1 2 3] [4 5 6]] key is [7 8 9] after append: [[7 8 9] [7 8 9] [7 8 9]] // why even this? any thoughts? Thanks! -- 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.