Message Boards Message Boards

1
|
4991 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

What `Dynamic[expr,f]` is really about?

Posted 9 years ago

I so understand that the construct Dynamic[expr,f] is to take the exp and evaluate f[exp] and return f , however the code below doesn't seem to return w, why?

InputField[Dynamic[pp]]
Dynamic[pp, {(pp = #; w = pp^2) &} ]
Dynamic[w]
POSTED BY: Al Guy
6 Replies
Posted 9 years ago

Because the interactive symbol that is entered is being used in many parts of the program with Dynamics.

POSTED BY: Al Guy

You can use TrackedSymbols :> and put there what you want to trigger this Dynamic. Why isn't my first solution ok?

POSTED BY: Kuba Podkalicki
Posted 9 years ago

Can I make it in such a way so that it will evaluate the stufftodo not in continuously monitoring manner but rather after (or while) I finished editing InputField[Dynamic[pp]] like the second argument options in Dynamics?

POSTED BY: Al Guy

Interactivity is between you and the InputField. Standalone Dynamic is updated automatically so, according to the definition, it does not care about it's second argument.

If you want standalone Dynamic to behave that way you have to use DynamicWrapper or equivalent

Dynamic[stuffToDo; stuffToDisplay]
POSTED BY: Kuba Podkalicki
Posted 9 years ago

I still don't understand. In my code InputField[Dynamic[pp]] interactivly changes the value of pp, so Dynamic[pp, {(pp = #; w = pp^2) &} ] should automatically update the value of w with your expalantion.

POSTED BY: Al Guy

Quote from docs for Dynamic:

continually evaluates f[val,expr] during interactive changing or editing of val.

which explains why your Dynamic is not touching w.

Dynamic[pp, {(pp = #; w = pp^2) &} ] is not interactively changed but automatically when you interactively change InputField content.

Following those points, your code should be rewritten to:

InputField[Dynamic[pp, {(pp = #; w = pp^2) &}]]
Dynamic[pp]
Dynamic[w]
POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract