On Sat, Sep 15, 2012 at 12:06 AM, Larry Clapp <
la...@theclapp.org> wrote:
> Append returns a value, in case it has to expand the array backing the
> slice. You need to say
>
> store = append(store, obj)
>
> But I think even that is wrong, because I don't think the store from main()
> is updated. (But I could be wrong; I'm not clear on the semantics of
> assigning to a slice.)
slices are just like every other value in Go, nothing magical about them.
> Anyway, you might need to say
>
> package main
>
> func save(obj chan int, store *[]chan int) {
> *store = append(*store, obj)
> }
>
> func main() {
> store := make([]chan int, 0)
> obj := make(chan int, 10)
> save(obj, &store)
> }
Since append() can allocate a new underlying array from the store
slice, you do need some way of communicating this change up the stack.
You can either do this by updating a pointer(as is the example above)
or you can have your function return the value.
Ignoring the value isn't an option.
--
=====================
http://jessta.id.au