Message Boards Message Boards

0
|
2491 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Save Dynamic variable's content, not its name

Posted 2 years ago

Here is a simplified version of a problem I've run into in a large project:

Module[{testA, testB},
 testA = {1, 2, 3};
 testB = {Blue, Dynamic[testA]};
 testA = {4, 5, 6};
 Save["/Users/markgreenberg/Desktop/testing.wl", {testA, testB}]
 ]

I desire the saved output to be {RGBColor[0, 0, 1], {4, 5, 6}}, but instead I get {RGBColor[0, 0, 1], testA\ $154804}. I know that testA\$154804 is the variable name altered by Module, but I want the saved output to be that variable's current content. There's got to be an easy way to do this. Can anyone please point me in the right direction?

Thanks

POSTED BY: Mark Greenberg
5 Replies

A slight variation:

DynamicModule[{testA, testB},
  testA = {1, 2, 3};
  testB = Dynamic@{Blue, testA};
  testA = {4, 5, 6};
  Print[{testA, testB[[1]]}]];
POSTED BY: Gianluca Gorni
Posted 2 years ago

Wow, this is like the hidden secrets of the Wolfram Language. You can't see part 1 of the dynamic expression even in FullForm, but it's there. Between your code and Henrik's, I'll be able to solve the problem in my project. Thank you, Gianluca.

POSTED BY: Mark Greenberg

Mark,

I hope I am not missing the point by making some changes:

  • I think in this context DynamicModule should be used (instead of Module).
  • Save seems to be for saving symbols; does Export work for you?
  • regarding your actual question: The only solution I can come up with is to remove Dynamic from your final expression.

    DynamicModule[{testA, testB},
     testA = {1, 2, 3};
     testB = {Blue, Dynamic[testA]};
     testA = {4, 5, 6};
     Refresh[testA, None];
     Export["testing.wl", {testA, testB} /. Dynamic[expr_] :> expr]]
    

Does that help? Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 2 years ago

Thanks for your response, Henrik. Your code does produce the desired effect. It seems that the Refresh function is not necessary, at least in the context of my project. Stripping the expression of its dynamic wrapper solved the problem. I was not aware of the difference between Save and Export. I'll use Export from now on for tasks like this.

Again, many thanks.

POSTED BY: Mark Greenberg

Hi Mark,

of course Refresh is not necessary! I tried several things, and this one I simply forgot to delete - sorry! Glad I could help, but I still hope for some cleaner solution from others.

Cheers -- Henrik

POSTED BY: Henrik Schachner
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