7
$\begingroup$

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 Protected attribute which decides what is going to be stored? Because there is no problem if f:=SystemID but:

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

Edit:

  • Why MachineID is not protected? - The bounty is founded for this question.
$\endgroup$
13
  • $\begingroup$ Nice question! I agree that it seems odd that $MachineID is not Protected $\endgroup$ Commented Aug 27, 2013 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$ Commented Aug 27, 2013 at 11:45
  • $\begingroup$ ah yes, I guess that could be a privacy issue. $\endgroup$ Commented Aug 27, 2013 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$ Commented Aug 27, 2013 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$ Commented Mar 12, 2014 at 11:21

2 Answers 2

7
$\begingroup$

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]; 
$\endgroup$
2
  • $\begingroup$ Thank you, it seems I have to dig more in documentation next time :) $\endgroup$ Commented Aug 27, 2013 at 11:05
  • 5
    $\begingroup$ Don't you think it is strange that $MachineID is not protected? $\endgroup$ Commented Aug 27, 2013 at 11:05
3
$\begingroup$

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 = Function[ 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

Select[list, Function[Not[FreeQ[#, "failure"]] && FreeQ[#, Protected]]] // Column (*output*) {$ActivationGroupID,failure} {$ActivationKey,failure} {$ActivationUserRegistered,failure} {$InputFileName,failure} {$LicenseExpirationDate,failure} {$LicenseID,failure} {$LicenseProcesses,failure} {$LicenseServer,failure} {$LicenseSubprocesses,failure} {$LicenseType,failure} {$MachineAddresses,failure} {$MachineDomain,failure} {$MachineDomains,failure} {$MachineID,failure} {$MachineName,failure} {$MaxLicenseProcesses,failure} {$MaxLicenseSubprocesses,failure} {$NetworkLicense,failure} {$ParentProcessID,failure} {$PatchLevelID,failure} {$ProcessID,failure} {$UserName,failure} 
$\endgroup$
3
  • $\begingroup$ Thanks, I'm curious why it is so. Btw. what causes the error masg if the symbol is not protected? $\endgroup$ Commented Aug 27, 2013 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$ Commented Aug 27, 2013 at 12:33
  • $\begingroup$ this answer by rm-rf is related. $\endgroup$ Commented Mar 12, 2014 at 11:22

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.