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?
AtomQ
part of question I do not see a difference to sayGraph
. 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$TreeForm[Plus[1, Unevaluated@Association["x" -> y]]]
willl not show an atomic structure. This is very depending on the evaluation process... $\endgroup$Association
is both a constructor and a container? For example,Hold[<|1 -> 1|>] === With[{x = <|1 -> 1|>}, Hold[x]]
evaluates toFalse
, indicating that there is some construction step going on that makes a constructed association different from the raw input. $\endgroup$