# Relation between the syntactic and evaluated Association

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:

Clear[y];
assoc = <|"x" -> y|>;
y = 0;
assoc

<|"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|>

True

False

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

2

3


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?

• Of interest, this comment. – user31159 Sep 10 '16 at 14:27
• 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... – gwr Sep 10 '16 at 14:41
• Note, that TreeForm[Plus[1, Unevaluated@Association["x" -> y]]] willl not show an atomic structure. This is very depending on the evaluation process... – gwr Sep 10 '16 at 15:16
• These are two very interesting questions and I think they would be better answered if posed separately. Hence my close vote. – István Zachar Nov 5 '18 at 8:55
• 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. – Sjoerd Smit Nov 5 '18 at 11:24