# List[...] + Association[...], or Association[...] + List[...], when does the order matter?

Values of a list can be added to an association's values like so,

<|"a" -> 10, "b" -> 10, "c" -> 10|> + {1, 2}

(*  {<|"a" -> 11, "b" -> 11, "c" -> 11|>, <|"a" -> 12, "b" -> 12, "c" -> 12|>} *)


The order does not matter:

{1, 2} + <|"a" -> 10, "b" -> 10, "c" -> 10|>

(*  {<|"a" -> 11, "b" -> 11, "c" -> 11|>, <|"a" -> 12, "b" -> 12, "c" -> 12|>} *)


Except when {1, 2} is replaced by Range[2]:

<|"a" -> 10, "b" -> 10, "c" -> 10|> + Range[2]

(*  {<|"a" -> 11, "b" -> 11, "c" -> 11|>, <|"a" -> 12, "b" -> 12, "c" -> 12|>} *)

Range[2] + <|"a" -> 10, "b" -> 10, "c" -> 10|>

(*  <|"a" -> {11, 12} "b" -> {11, 12} "c" -> {11, 12}|> *)


Here, argument order matters. Trace shows that Range[2] is evaluated first in both cases, so why the different behaviour?

It's probably a bug related to packed arrays:

<|"a" -> 10, "b" -> 10, "c" -> 10|> + DeveloperToPackedArray[{1, 2}]
(*  {<|"a" -> 11, "b" -> 11, "c" -> 11|>, <|"a" -> 12, "b" -> 12, "c" -> 12|>}  *)

DeveloperToPackedArray[{1, 2}] + <|"a" -> 10, "b" -> 10, "c" -> 10|>
(*  <|"a" -> {11, 12}, "b" -> {11, 12}, "c" -> {11, 12}|>  *)


It should be reported to WRI.

• I reported it to WRI. Commented Jun 18 at 19:34