The argument could be that slices are read-only too. Just that "append" is special and it makes zero value slices useful.var a []inta[0] = 1 // Fails.// panic: runtime error: index out of rangeI am just curious what is the reason behind not making zero maps more useful? Is it space?
I'm not sure what you mean by the append doesn't modify the original. Append will use the same backing store (if there is available capacity in it) and by definition the address of the slice in question must be invariant across its context. e.g.: https://play.golang.org/p/lBRpKSo-9PI think of a slice as a built in structure so the pointer to the backing store will stay the same, the capacity will stay the same, only the length will change with append. (unless there is insufficient capacity then all bets are off except that again the original structure will remain, but all the values in it will be overwritten, then copied back into the original struct)Or have I really misunderstood what happens under the hood here?
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-j