This question is inspired by this answer and related to unsolved post "Association's Attributes change between 10.3.1 & 10.4".

Consider the case of pre-evaluated Association:

assoc = <|"x" -> y|>;
y = 0;
<|"x" -> y|>

However with the above definition for y we get for a new Association:

<|"x" -> y|>
<|"x" -> 0|>

The first question: what prevents assoc from being further evaluated to <|"x" -> 0|> and why the new Association doesn't hold its arguments?

The second question is related to the structure of Association. Let us compare evaluated and unevaluated Association:

AtomQ@<|"x" -> y|>
AtomQ@Unevaluated@<|"x" -> y|>

Depth[<|"x" -> y|>]
Depth[Unevaluated@<|"x" -> y|>]


Despite the above TreeForm in the both cases shows that we have atomic objects:

TreeForm[<|"x" -> y|>]
TreeForm[Unevaluated@<|"x" -> y|>]



So, is Association atomic or not? How to understand this controversy? Is there a special internal definition for Association causing this behavior?

  • 4
    $\begingroup$ Of interest, this comment. $\endgroup$
    – user31159
    Sep 10, 2016 at 14:27
  • $\begingroup$ Regarding the AtomQ part of question I do not see a difference to say Graph. Unless with raw objects like stings or numbers, the head must be evaluated so that the atomic quality is recognized, mustn't it? For example, a Graph-object with a false body will not be an atom... $\endgroup$
    – gwr
    Sep 10, 2016 at 14:41
  • $\begingroup$ Note, that TreeForm[Plus[1, Unevaluated@Association["x" -> y]]] willl not show an atomic structure. This is very depending on the evaluation process... $\endgroup$
    – gwr
    Sep 10, 2016 at 15:16
  • $\begingroup$ These are two very interesting questions and I think they would be better answered if posed separately. Hence my close vote. $\endgroup$ Nov 5, 2018 at 8:55
  • 3
    $\begingroup$ Isn't this because Association is both a constructor and a container? For example, Hold[<|1 -> 1|>] === With[{x = <|1 -> 1|>}, Hold[x]] evaluates to False, indicating that there is some construction step going on that makes a constructed association different from the raw input. $\endgroup$ Nov 5, 2018 at 11:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.