On Fri, Jan 11, 2013 at 10:41 AM, Matthew Dempsky <
mdem...@google.com> wrote:
> The January 9, 2013 spec says this about iterating over a map:
>
> "If map entries are inserted during iteration, the behavior is
> implementation-dependent, but the iteration values for each entry will be
> produced at most once."
>
>
> Does "for each entry" here mean "for each map entry" or "for each inserted
> entry"?
For each inserted entry. Conceptually, inserting an entry should not
disturb the map iteration, but the new key may be before or after the
current iteration point so whether the new key is returned during the
iteration is implementation dependent.
> For example, consider the following code:
>
> m := make(map[int]int)
> for i := 0; i < 10; i++ {
> m[i] = i
> }
> for k := range m {
> fmt.Println(k)
> m[100] = 100
> }
>
> Is it conforming for an implementation to print out only a single value? Or
> is it required that the implementation should print (in an undefined order)
> 0 through 9 and possibly (at the implementation's discretion) 100?
The latter.
Ian