# How to overwrite a private symbol value temporarily?

I have a package file mypackage.m with

BeginPackage["FooBar"]
Begin["Private"]
tmp=2;
foo=2*tmp;
myprogram[foo]
...
End[]
EndPackage[]


The file is VCS controlled. For some reason, I need to Get mypackage.m with the effect of tmp being 3 instead of 2, but I'd like to avoid explicitly changing tmp=2 to tmp=3 in the working copy of mypackage.m and having the VCS flagging it as locally modified. Any way I can modify the way of loading the file

Get["mypackage.m"]


• @Yi Wang, your suggestion is incorrect if you mean Block[{tmp = 3}, Get["mypackage.m"]]. Also your comment is too undetailed to be understandable or helpful. Sep 16, 2014 at 7:50
• Sorry I misunderstood your question... Sep 16, 2014 at 8:03
• What's the context of tmp? Suppose it's Global, then how about tmp = 3; SetAttributes[tmp, Protected]; Get["mypackage.m"]? And tmp in a different context can be modified in a similar way. Sep 16, 2014 at 8:08
• @xzczd I amended original post to clarify it. Sep 16, 2014 at 8:18

You can first Protect the tmp (of course with its Context added) and then call the package i.e.:

FooBarPrivatetmp = 3;
Protect[FooBarPrivatetmp]
(* Or you can use: *)
(* SetAttributes[FooBarPrivatetmp, Protected] *)
<< "mypackage.m"


A warning will come out but it doesn't matter.

• Only thing I added is after Get[], I do SetAttributes[FooBarPrivatetmp, Unprotected] Sep 17, 2014 at 4:27
• @qazwsx I think there's no attribute named Unprotected, to clear the attribute Protected you can use Unprotect[FooBarPrivatetmp] or ClearAttributes[FooBarPrivatetmp, Protected] :) Sep 17, 2014 at 4:46
• Yes. ClearAttributes[FooBarPrivatetmp, Protected]. Also Quiet[Get["mypackage"], Set::wrsym]. Sep 17, 2014 at 5:09
• @qazwsx You can type " \ " instead of " ` " to make it display correctly inside the code block :) Sep 17, 2014 at 5:17
• Yes, I'm well aware. Sep 17, 2014 at 5:28