12
$\begingroup$

Edit: I changed the title and (slightly) the wording of this question in order to make it more easily answerable.

If I evaluate this in Mathematica 9:

SetAttributes[foo, HoldFirst]
foo[x_] :=
 (T`var := x;
  DeleteFile["thisisatest"];
  Save["thisisatest", "T`"]
 )

foo[$ProcessID]

The resulting saved file looks like this:

T`var := $ProcessID

$ProcessID = 6903

If I evaluate Get["thisisatest"], mathematica complains that I shouldn't be setting the value of special symbol $ProcessID. If I change Save to DumpSave and try again, Get no longer triggers the complaint. Examination of the saved file in a text editor shows no evidence of a stored value for $ProcessID, though it's a little hard to tell.

The behavior I want is that of DumpSave, but platform independent. The documentation seems to suggest that these two functions would be interchangeable, except that Save will append to an existing file. What are the known differences between the two functions in practice, and how does one account for them?

$\endgroup$
5
  • 2
    $\begingroup$ Just a guess: Save produces a file that, when evaluated, restores the values of symbols in T` . DumpSave creates a file that, when loaded, restores the in-memory state of whatever you saved from T` . It might not even save $ProcessID. The difference is evaluating something that recreates the state, or just loading the state directly. This is just a wild guess. I don't understand the internals. But I'd say not a bug. $\endgroup$
    – Szabolcs
    Commented Feb 10, 2013 at 1:39
  • 6
    $\begingroup$ I have encountered similar problem with Save converting delayed UpValues- based definitions to immediate ones (don't remember which one was the culprit - Save or Get), in this answer. Did not really find time to get deeper into it, but have a look at retrieveMainList function there for a work-around and some comments I made about it. $\endgroup$ Commented Feb 10, 2013 at 1:41
  • 1
    $\begingroup$ I've reworded the question from "is this a bug and what cases trigger it?" to ask "how do I get the behavior I want out of Save and DumpSave?" Barring an official response from Wolfram by somebody who has looked at the relevant code, the question in its original form was difficult to answer conclusively. Barring further activity (I'd still like to know if anyone has further observations about the differences between the two functions), I'll accept @LeonidShifrin's comment as an answer via a community wiki post. $\endgroup$ Commented Feb 10, 2013 at 19:48
  • $\begingroup$ @Tobias This is a good and important questions. Please wait a couple of days, I'd like to see more answers! $\endgroup$
    – Szabolcs
    Commented Feb 10, 2013 at 19:53
  • $\begingroup$ My comment certainly does not qualify as an answer, or I would have posted it as such :) $\endgroup$ Commented Feb 10, 2013 at 21:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.