1
$\begingroup$

When evaluating this, the final value of a is 0 as it should be, but Dynamic[a] shows a 1.

a = 0;
Dynamic[a]
Block[{a = 1}, Pause[1]; a];
(*1*)

When excluding all Pause calls, there is no bug.

a = 0;
Dynamic[a]
Block[{a = 1}, a];
(*0*)

Is it possible to force Dynamic to update without changing the value of a?

$\endgroup$
5
  • $\begingroup$ Have you seen Refresh as in Dynamic[Refresh[a, UpdateInterval->0]]? $\endgroup$
    – kale
    Jul 3, 2016 at 19:22
  • 1
    $\begingroup$ I suppose it is closely related to "Rare in Practice:" part of Albert's answer in How safe is the use of Block and Internal`InheritedBlock $\endgroup$
    – Kuba
    Jul 3, 2016 at 19:26
  • 1
    $\begingroup$ It happens to me if I replace Pause with Do[1, {10000000}]; -- I think it's a lengthy calculation that causes the system to update a when it is 1. $\endgroup$
    – Michael E2
    Jul 3, 2016 at 19:27
  • 1
    $\begingroup$ That one is better: mathematica.stackexchange.com/q/83035/5478 $\endgroup$
    – Kuba
    Jul 3, 2016 at 19:34
  • $\begingroup$ @Kuba I think that (Albert's answer) explains it. And Clear[a] solves it. Note that the second comes out 0 only because a is restored to 0 by the time the dynamic update executes. It's possible that it won't always be 0, I suppose, since there is a very small window between setting and restoring a (in the second example). $\endgroup$
    – Michael E2
    Jul 3, 2016 at 19:34

0

Browse other questions tagged or ask your own question.