Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread Burak Serdar
On Tue, Mar 6, 2018 at 2:58 PM, Bharath Ram wrote: > In that case, for a nested struct from top to bottom, all the values are > copies as values, correct? i.e, string, int, float, array etc will be copied > by value & map, slice, channel etc will be copied as pointers if they are > initialized? >

Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread Bharath Ram
Thanks a lot! On Mar 6, 2018 5:22 PM, "Burak Serdar" wrote: > On Tue, Mar 6, 2018 at 2:58 PM, Bharath Ram > wrote: > > In that case, for a nested struct from top to bottom, all the values are > > copies as values, correct? i.e, string, int, float, array etc will be > copied > > by value & map,

Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread Bharath Ram
In that case, for a nested struct from top to bottom, all the values are copies as values, correct? i.e, string, int, float, array etc will be copied by value & map, slice, channel etc will be copied as pointers if they are initialized? https://play.golang.org/p/NzH8LVyQ0rp code works as I wan

Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread Dave Cheney
On Wednesday, 7 March 2018 07:39:56 UTC+11, andrey mirtchovski wrote: > > maybe this will give you a hint: https://play.golang.org/p/ANIjc3tCdwp > > maps are reference types, but they still get passed by value. > Maps are pointers, pointers are values. -- You received this message because yo

Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread Burak Serdar
On Tue, Mar 6, 2018 at 1:23 PM, wrote: > go version 1.10 > > > Operating system and processor architecture > > GOHOSTARCH="amd64" > GOHOSTOS="darwin" > However, this happens in play.golang.org env as well. > > > Checkout the code. > > https://play.golang.org/p/v6u7R_nbGRp doc1 := Document{} //

Re: [go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread andrey mirtchovski
maybe this will give you a hint: https://play.golang.org/p/ANIjc3tCdwp maps are reference types, but they still get passed by value. if you pass a nil map around, the old value you passed will not magically start pointing to a new map once you instantiate it elsewhere. -- You received this messa

[go-nuts] Pass by value in struct not yielding expected result

2018-03-06 Thread bharathramh92
go version 1.10 Operating system and processor architecture GOHOSTARCH="amd64" GOHOSTOS="darwin" However, this happens in play.golang.org env as well. Checkout the code. https://play.golang.org/p/v6u7R_nbGRp In the example, if the struct (Document) is not initialized at first, there is no pl