5
$\begingroup$

If I create a stream,

str = StringToStream["how can I dynamically display the stream position"];
Read[str, Word]

"how"

then, when I use,

Dynamic[StreamPosition[str]]

The output will not dynamically update the current state of the stream position.

Any ideas?

$\endgroup$
3
  • $\begingroup$ Same issue with Dynamic[Streams[ ]] $\endgroup$ Commented Nov 20, 2015 at 20:39
  • $\begingroup$ A workaround, of course Dynamic[Refresh[Streams[], UpdateInterval -> 1]] $\endgroup$ Commented Nov 20, 2015 at 20:46
  • 1
    $\begingroup$ The stream str contains only stream ID and it never changes. You can obtain full stream information with Internal`StreamInformation[str]. Unfortunately, It doesn't solve the problem. $\endgroup$
    – ybeltukov
    Commented Nov 20, 2015 at 21:46

1 Answer 1

4
$\begingroup$

To not prompt Dynamic each second or something, let's create useless variable that will prompt it.

Dynamic[T`r; StreamPosition[str]]
read = (T`r = Read[##]) &;
read[str, Word]
$\endgroup$
4
  • $\begingroup$ Veggy, veggy nice! $\endgroup$ Commented Nov 20, 2015 at 21:43
  • $\begingroup$ Well done! could you perhaps explain the mechanics behind these notations? i.e. the " ` " $\endgroup$ Commented Nov 20, 2015 at 23:00
  • $\begingroup$ @peter I just used T contex to not pollute the default Global` . $\endgroup$
    – Kuba
    Commented Nov 20, 2015 at 23:29
  • $\begingroup$ @Kuba cool, thanks $\endgroup$ Commented Nov 20, 2015 at 23:49

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.