Bug introduced in 9.0 or earlier, persisting through 13.2 or later

In a nutshell, why does this work (change y and see how the value updates)

 Initialization :> (x = Symbol["y"])]

and then on a separate cell

y = 98;

but this doesn't? (assign the printed variable whatever value and see how it doesn't update)

 Initialization :> (x = Unique[])]

You can also write Dynamic[the printed var] in a separate cell and see how it doesn't update either.

For now, I'll be using something that works and I would have never thought I would be using

 Initialization :> (x = (Remove[#]; Symbol[#]) &@ToString@Unique[])]

My current weird conclusion: "If a variable was declared by Unique[] inside a Dynamic update, then it will never be tracked by any Dynamic "

  • $\begingroup$ Does using Unique["xx"] make any difference? $\endgroup$
    – Mr.Wizard
    Commented Aug 11, 2012 at 14:35
  • $\begingroup$ @Mr.Wizard no it doesn't. Neither does Unique["Global`blah"] $\endgroup$
    – Rojo
    Commented Aug 11, 2012 at 14:38
  • 3
    $\begingroup$ This has to do with Dynamic executing asynchronously. When given together in one cell block y=98 is already executed before the Dynamic is fully finished. $\endgroup$ Commented Aug 12, 2012 at 7:06
  • 2
    $\begingroup$ I give up. Shall we call it a bug? $\endgroup$ Commented Aug 12, 2012 at 21:34
  • 3
    $\begingroup$ @SjoerdC.deVries sure. I should mail Wolfram and see what comes back $\endgroup$
    – Rojo
    Commented Aug 12, 2012 at 23:11

1 Answer 1


I attempted this

With[{z = Unique[]}, Dynamic[w, Initialization :> (w = z)]]

and it prints \$nnn for some nnn. Then if you update the var \$nnn in other cell it gets updated. This may be a better code that the one you found.

I thought about why, but couldn't explain it. It seems Dynamic understands Symbol but doesn't understand Unique. The introduction of With seems to solve the shortcoming in Dynamic and I was speculating about a syntactic construct there but deleted my reply as it doesn't explain why Dynamic still works with Symbol.

Anyway, hope helps.

  • $\begingroup$ Thanks. This solves the updating issue, probably because the Unique isn't called during a dynamic update. However, for the same reason, it doesn't serve the same purpose as the original code. If you run this code, then Quit the kernel, and then start using Unique or perhaps even Module somewhere else, you might end up with the same variable name as in this dynamic cell... $\endgroup$
    – Rojo
    Commented Jan 8, 2013 at 13:45
  • $\begingroup$ I'm actually thinking of posting and accepting an answer such as "variables declared by Unique inside a Dynamic can't be tracked. I don't know if this is intended behaviour, but based on the comments it seems it isn't, and it has been reported". I was just hoping of some miracle explanation or setting $\endgroup$
    – Rojo
    Commented Jan 8, 2013 at 13:46
  • $\begingroup$ @rojo, I believe you should say "symbols created with Unique" instead of variables. The oddity is that symbols created with Symbol still work. So I bet Dynamic does more than a simple syntactic (but at runtime) resolution of dependency. $\endgroup$
    – carlosayam
    Commented Jan 8, 2013 at 20:38

Your Answer

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

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