I want to construct an association that some of the Values
are constructed from other parts of the Values
, for the simplest example
assoc=<|
"a"->1,
"b"->assoc["a"]
|>;
The output I desired is
<|a->1,b->1|>
but to get this result we need to evaluate the Set
twice
assoc=<|
"a"->1,
"b"->assoc["a"]
|>;
and the first evaluation returns
<|a->1,b->assoc[a]|>
I believe this is related to the inner construction of association, see https://mathematica.stackexchange.com/a/128456/86893.
Notice that this feature is different from the sequential CompoundExpression[a=1,b=a]
;
Is there some trick to bypass this problem?
The real example is much complicated than this example. What I want is a method similar to the "in-place evaluation trick". I have tried RuleCondition
but failed for this example.
The method I currently use is like
assoc=<|
"a"->1
|>
assoc=<|
assoc,
"b"->assoc["a"]
|>
As you can see, for more complicated situations this get harder to read and organize.