Is there a way to set what symbols's definitions I do not want to store?
Consider the following code:
f := $MachineID;
SetDirectory[NotebookDirectory[]];
Save["testm.m", f];
ClearAll@f
<< "testm.m"
f
Set::specset: Cannot change the value of special symbol $MachineID. >>
0000-00000-00001 (*id of storing machine*)
0000-00000-00002 (*id of getting machine*)
This happens bacause testm.m contains:
f := $MachineID
$MachineID = "0000-00000-00001"
Questions:
Is there nicer way to avoid this than my approach:
f:= Symbol["MachineID"]?
Is it
Protectedattribute which decides what is going to be stored? Because there is no problem iff:=SystemIDbut:Attributes[{$SystemID, $MachineID}]{{Locked, Protected}, {}}
Edit:
- Why
MachineIDis not protected? - The bounty is founded for this question.
Answer
From the documentation:
Save: Save uses FullDefinition to include subsidiary definitions.
FullDefinition: FullDefinition[symbol] recursively prints as all definitions for the symbol, and for the symbols that appear in these definitions, unless those symbols have the attribute Protected.
So if you want to not save $MachineID you could do:
Protect[$MachineID];
Save["testm.m", f];
Unprotect[$MachineID];
Comments
Post a Comment