Re: [go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Jan Mercl
On Thu, Jul 7, 2016 at 4:41 PM Jesse McNelis wrote: > Looks fine to me. The k in m[k] is the value of k before the assignment. > > So the value at m["foo"] is assigned to m[""] and the value at m["bar"] is assigned to m["foo"] Took me a while to run it through a mind emulator, but you're right.

Re: [go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Jesse McNelis
On 8 Jul 2016 12:19 a.m., "Jan Mercl" <0xj...@gmail.com> wrote: > > I did not expect the result I've got: https://play.golang.org/p/ECno0PVdBF > > It seems like a bug to me. > Looks fine to me. The k in m[k] is the value of k before the assignment. So the value at m["foo"] is assigned to m[""] a

Re: [go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Konstantin Khomoutov
On Thu, 07 Jul 2016 14:19:17 + Jan Mercl <0xj...@gmail.com> wrote: > > for k, m[k] := range m {...} > > > > Apparently is valid Go syntax, however what are the semantics > > behind this? > > It is not a valid Go syntax. The short variable declaration syntax > requires variable names on its le

Re: [go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Jan Mercl
On Thu, Jul 7, 2016 at 4:06 PM Kyle Stanly wrote: > for k, m[k] := range m {...} > > Apparently is valid Go syntax, however what are the semantics behind this? It is not a valid Go syntax. The short variable declaration syntax requires variable names on its left side. You probably meant '=' inst

[go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Kyle Stanly
I noticed that the specification states: "As with an assignment, if present the operands on the left must be addressable or map index expressions; they denote the iteration variables." Here is the thing I am having trouble imagining... if the iterator keeps a snapshot of the map at the time th