Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-03-14 Thread 'Axel Wagner' via golang-nuts
On Sat, Mar 14, 2020 at 2:47 AM wrote: > However I always need a map that is initialized in future downpath code. > ( i use it in a range statement that just noops if it is empty) > It will also noop if the map is nil . > This code has to be optimized in

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-03-14 Thread roger peppe
In this particular case, couldn't you just check for len(m) == 0 ? i.e. assume that any zero size map is the shared one? On Sat, 14 Mar 2020, 01:46 , wrote: > I have a use for this that is not covered it seems. > > So basically I am runnning a code that may or may not create a map > depending on

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-03-13 Thread dtracers
I have a use for this that is not covered it seems. So basically I am runnning a code that may or may not create a map depending on if it needs to fill it with items. However I always need a map that is initialized in future downpath code. ( i use it in a range statement that just noops if it i

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-12 Thread Jake Montgomery
The playground is your friend: https://play.golang.org/p/p10XugRD4_z So, the answer is no. On Tuesday, February 11, 2020 at 6:56:05 PM UTC-5, Kevin Regan wrote: > > Would something like this work: > > m1 := make(map[string]string) > m2 := m1 > > if &m1 == &m2 { >... > } > > > On Tue, Feb 11, 2

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-11 Thread Ian Lance Taylor
On Tue, Feb 11, 2020 at 3:55 PM 'Kevin Regan' via golang-nuts wrote: > > Would something like this work: > > m1 := make(map[string]string) > m2 := m1 > > if &m1 == &m2 { >... > } That would do something but it's not a particularly interesting property. I'm not sure what you are trying to che

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-11 Thread Ian Lance Taylor
On Tue, Feb 11, 2020 at 5:51 AM roger peppe wrote: > > I believe that the main reason that equality isn't defined on maps (and > slices) is to preserve the future possibility that equality might work at a > whole-value level rather than on a reference level. I suspect that one of > these days a

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-11 Thread 'Kevin Regan' via golang-nuts
Would something like this work: m1 := make(map[string]string) m2 := m1 if &m1 == &m2 { ... } On Tue, Feb 11, 2020 at 5:50 AM roger peppe wrote: > I believe that the main reason that equality isn't defined on maps (and > slices) is to preserve the future possibility that equality might work

Re: [go-nuts] Re: Checking if two map variables refer to the same map

2020-02-11 Thread roger peppe
I believe that the main reason that equality isn't defined on maps (and slices) is to preserve the future possibility that equality might work at a whole-value level rather than on a reference level. I suspect that one of these days a final decision will be made... On Mon, 10 Feb 2020 at 23:42, '

[go-nuts] Re: Checking if two map variables refer to the same map

2020-02-10 Thread 'Kevin Regan' via golang-nuts
I just ran into this... ...makes me like go a little less. On Tuesday, August 7, 2018 at 6:34:03 AM UTC-7 mi...@daglabs.com wrote: > Sorry for bumping a very old thread, but I absolutely disagree with the > people stating that this problem is contrived, and I got here from a Google > search, s

[go-nuts] Re: Checking if two map variables refer to the same map

2018-08-07 Thread mike
Sorry for bumping a very old thread, but I absolutely disagree with the people stating that this problem is contrived, and I got here from a Google search, so this might be relevant for some people. A very real use-case for reference-comparing maps is when testing .Clone() methods. You want to