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-9P
I 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?

On Tuesday, 18 April 2017 13:09:11 UTC+1, Ian Davis wrote:
>
>
> On Tue, 18 Apr 2017, at 01:04 PM, Tad Vizbaras wrote:
>
>
> The argument could be that slices are read-only too. Just that "append" is 
> special and it makes zero value slices useful.
> var a []int
> a[0] = 1 // Fails.
> // panic: runtime error: index out of range
>
> I am just curious what is the reason behind not making zero maps more 
> useful? Is it space?
>
>
> A nitpick: slices are always read only. append creates a new slice, it 
> doesn't modify the original.
>
> In that respect map and slice zero value behaviours are similar.
>
> Ian
>

-- 
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.

Reply via email to