Is there a way to set what symbols's definitions I do not want to store?

Consider the following code:

f := $MachineID;
Save["testm.m", f];


<< "testm.m"
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"


  • Is there nicer way to avoid this than my approach:

    f:= Symbol["MachineID"] 


  • Is it Protected attribute which decides what is going to be stored? Because there is no problem if f:=SystemID but:

    Attributes[{$SystemID, $MachineID}]
    {{Locked, Protected}, {}}


  • Why MachineID is not protected? - The bounty is founded for this question.
  • $\begingroup$ Nice question! I agree that it seems odd that $MachineID is not Protected $\endgroup$ Aug 27 '13 at 11:42
  • $\begingroup$ @JacobAkkerboom Hello,:) yes, in fact I wouldn't have known this but there is something else what causes the error msg and without this my MachineID could have been distributed :D. $\endgroup$
    – Kuba
    Aug 27 '13 at 11:45
  • $\begingroup$ ah yes, I guess that could be a privacy issue. $\endgroup$ Aug 27 '13 at 12:03
  • 2
    $\begingroup$ I am unhappy that you have asked two very different questions here causing two separate answer threads to come into existence for this one question. It makes a confusing mess for anyone trying to figure out what this post is really about. You really should have posted two questions. $\endgroup$
    – m_goldberg
    Aug 27 '13 at 21:46
  • 1
    $\begingroup$ Related: Why the Block command does not forget the $ContextPath variable. Perhaps we should investigate the extent of this relation, rm-rfs list is similar to mine, but not the same. $\endgroup$ Mar 12 '14 at 11:21

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:

Save["testm.m", f];
  • $\begingroup$ Thank you, it seems I have to dig more in documentation next time :) $\endgroup$
    – Kuba
    Aug 27 '13 at 11:05
  • 5
    $\begingroup$ Don't you think it is strange that $MachineID is not protected? $\endgroup$
    – Kuba
    Aug 27 '13 at 11:05

Extended comment

I found the following interesting. I guess this happens for more Symbols than just $MachineID. The following tries to assign to special symbols starting with a $ and gives an overview of whether that was allowed and what the attributes are. Warning: you may want to restart the kernel after this.

list =
      xxxx, {HoldForm[xxxx], Check[xxxx = xxxx; "succes", "failure"], 
       Sequence @@ Attributes[xxxx]}, HoldAllComplete] @@ 
     ToExpression[#, InputForm, HoldComplete] & /@ 
   DeleteCases[Names["$*"], "$PrePrint" | "$Pre" | "$Post"];
list // TableForm
(*gives a big table*)

The following then gives a list of symbols similar to $MachineID in this respect

  Function[Not[FreeQ[#, "failure"]] && FreeQ[#, Protected]]] // Column


  • $\begingroup$ Thanks, I'm curious why it is so. Btw. what causes the error masg if the symbol is not protected? $\endgroup$
    – Kuba
    Aug 27 '13 at 12:28
  • $\begingroup$ @Kuba I don't know, the documentation has no special entry on this message. I suppose that that is a specific message just for special symbols. That is, the ones above, and probably similar symbols that do have Protected as well. $\endgroup$ Aug 27 '13 at 12:33
  • $\begingroup$ this answer by rm-rf is related. $\endgroup$ Mar 12 '14 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.