5
$\begingroup$

Bug introduced in 10.4 or earlier and persisting through 11.1.1

CASE:3892974

Thanks for bringing this to our attention. A report has been filed with the developers.


I can track changes to a list with Dynamic without too much difficulty

foolist = {};
Dynamic[foolist]

And if I were to append an element to foolist, the dynamic expression will refresh to {list}

AppendTo[foolist, list]

But when I do the same with an association,

foobar = <||>;
Dynamic[foobar]

And add a new entry to it

AssociateTo[foobar, foo->bar]

The dynamic expression won't be able to capture the change. Am I doing something wrong?

$\endgroup$
  • 2
    $\begingroup$ I don't think you do anything wrong, unless I'm missing something I think you should report this. p.s. notice that you can still do AppendTo[foobar, foo -> bar] and it will work well. $\endgroup$ – Kuba May 18 '17 at 18:40
  • $\begingroup$ @Kuba Ah thanks! And it seems that all Set assignments to an association can be tracked as well $\endgroup$ – arax May 18 '17 at 20:50
  • $\begingroup$ Indeed. I've reported that, will let you know in case of any news. (CASE:3892974) $\endgroup$ – Kuba May 18 '17 at 21:38
1
$\begingroup$

Meanwhile you can use:

AppendTo[foobar, foo->bar]

or more functional style:

foobar = <|foobar, foo->bar|>;

foobar = Append[foobar, foo->bar];
$\endgroup$
  • $\begingroup$ Won't the result of the "more idiomatic" be an undesirable <|<||>, foo->bar|>? $\endgroup$ – LLlAMnYP May 20 '17 at 15:27
  • $\begingroup$ @LLlAMnYP I don't understand, have you tried? But maybe I shoud've said "more functional style". $\endgroup$ – Kuba May 20 '17 at 16:40
  • $\begingroup$ since it's the weekend, no, I haven't. Are you saying, the first element won't be the empty association that foobar was before assignment? Since for, say, a list saying foobar={}; foobar={foobar, foo->bar} will give {{}, foo->bar} and not {foo->bar} $\endgroup$ – LLlAMnYP May 21 '17 at 17:03
  • $\begingroup$ @LLlAMnYP <|assoc1, assoc2|> works like Merge[{assoc1, assoc2}, Last] $\endgroup$ – Kuba May 21 '17 at 17:36
  • $\begingroup$ Interesting, so it autoflattens. $\endgroup$ – LLlAMnYP May 21 '17 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.