package main
import "fmt"
func main() {
// Create a slice of length 1 and capacity 2. Note: try changing this to make([]int, 1, 1) ...
a := make([]int, 1, 2)
// b "aliases" a
b := a
fmt.Printf("%v %v\n", a, b)
a = append(a, 2)
fmt.Printf("%v %v\n", a, b)
b = append(b, 5)
// Question : what does a contain now ?
fmt.Printf("%v %v\n", a, b)
}
http://play.golang.org/p/Hf2noTyNrpRun the program, change the capacity in the make call to 1, and re-run.
If they were values, a and b should simply diverge, so the last line should output [0 2] [0 5].
If they were references, then the last line should output [0 2 5] [0 2 5].
So slices (and maps) are neither values nor references. They're "half-references". Their length is passed as a value, their contents as a reference. Sort of like the linux kernel iovec structures, but completely hidden.
I would say this is a bug, as it violates both ways to think about these values. But it can't be changed without changing the complexity of lists in Go ... so this isn't going to change, and therefore will be declared "not a bug".