1

Dynamic[x=7]; does not make x dynamic! But Dynamic[x=7;] makes x dynamic with initial value 7. The problem with the later is the presence of Null in the output. My question is: how can I assign a (big) value (or a huge list, etc.) to a dynamic variable AND suppress any possible output (including Null)?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
kornaros
  • 1,047
  • 5
  • 14
  • 2
    What's the point of Dynamic then ? – b.gates.you.know.what Mar 05 '13 at 17:39
  • 2
    Have you investigated DynamicWrapper? – John Fultz Mar 05 '13 at 17:40
  • 1
    Read the tutorials on Dynamic. There's no such thing as a dynamic variable. There's only stuff that shows as the dynamically updated "current" value of an expression, and in the process of calculating that current value, it might update other "non-dynamic" variables – Rojo Mar 05 '13 at 17:58
  • I closed this question as a duplicate. (It is a common problem therefore "too localized" is inaccurate.) If anyone has a suggestion for a better duplicate (on Mathematica.SE) let me know. – Mr.Wizard Mar 05 '13 at 18:34
  • @Mr.Wizard Well, actually it's a duplicate of http://stackoverflow.com/questions/1179430/why-wont-this-work-dynamic-in-a-select/1581155#1581155 – Ajasja Mar 05 '13 at 19:11
  • @Ajasja I'm well aware of that, as you will see if you review my answer below and the question this one now redirects to. ;-) That's why I specifically said "on Mathematica.SE." – Mr.Wizard Mar 05 '13 at 20:54
  • @Mr.Wizard I apologize, I'm lacking a bit of eloquence today: I guess what I wanted to say was: "Could we not copy that answer to mma.se?". But there was probably some discussion on meta about such a policy already... – Ajasja Mar 05 '13 at 22:24
  • @Mr.Wizard Done – Ajasja Mar 05 '13 at 23:03

2 Answers2

3

Dynamic doesn't work the way you think it does. See this answer for a full explanation.

In short, Dynamic doesn't do anything until it is actually displayed on screen.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
1

Dynamic is only updated if it is displayed. Dynamic[]; is never displayed so it is never updated. Dynamic[...;] returns a dynamic that always returns Null, but is never the less updated.

Here is an example that demonstrates the problem:

x = .5;
Dynamic[Print["will not print:", x]];
Dynamic[Print["Should print:", x];]
Slider@Dynamic@x
Ajasja
  • 13,634
  • 2
  • 46
  • 104