Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

in the package I'm writing I have a list of global variables which should not be visible from a notebook. Here's an extract of the package:


(* Global variables *)
volumeTheorical = "Not calculated value";
absoluteErrorTheorical = "Not calculated value";
relativeErrorTheorical = "Not calculated value";
volumeReal = "Not calculated value";
absoluteErrorReal = "Not calculated value";
relativeErrorReal = "Not calculated value";
reserves = "";

volumeFitted[radiusFitted_] :=  volumeOfFittedTheoricalSphere[pointsCleaned[radiusFitted], radiusFitted];
pointsCleaned[radiusFitted_] :=   cleanPoints[generatePointsHemiSphere[radiusFitted]];
realPointsAdjusted[Diameter_, Anticlinal_, ConstantZ_] :=  cleanAdjustPoints[pointsCleaned[Diameter/2], Diameter, Anticlinal, ConstantZ];
constantH := 40;

and finally:


Anyway when I open a new notebook, after:


If I start to write, for example, constantH...the kernel shows me it already has it set to 40. Instead I'd like it not to be visible, so that any user can define it's own constantH and use it for something can I hide them? Thanks

share|improve this question

put on hold as off-topic by Louis, m_goldberg, MarcoB, Kuba, Edmund May 24 at 11:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Louis, m_goldberg, MarcoB, Kuba, Edmund
If this question can be reworded to fit the rules in the help center, please edit the question.

So, the variables should not be visible, but they, and their values, should still be usable, is that correct? Did you use an End in your package? What about BeginPackage and EndPackage? – Sjoerd C. de Vries Apr 9 '14 at 17:03
yes, the values and their values should be usable only in the package. I don't want the user to modify their values, only the package should. If I set them as Protected with SetAttributes[] it seems that the package doesn't work anymore... anyway in the end I have End[]; and then EndPackage[] – Lory Lory Apr 9 '14 at 17:16
Could you try saving the following in a text file ptest.m and then loading it with Needs? BeginPackage["ptest`"]; fun::usage = "fun[] returns the value of f\n"; Begin["`private`"] ; f = 1; fun[] := f; End[]; EndPackage[]; (everything on its own line). The local symbol f can now absolutely not be seen and happily co-exists with any global f-s you may define. You can see the local value of fusing fun[] or by using its full context ptest`private`f . – Sjoerd C. de Vries Apr 9 '14 at 18:16
sorry for the late...I've had some work troubles. Ok, I've just tried what you wrote and it works but I don't understand how I can use it in my case... :S – Lory Lory Apr 10 '14 at 13:59
If your package looks the same as my example it should work the same. Are you sure there are no fundamental differences? For instance, I don't see you using BeginPackage... – Sjoerd C. de Vries Apr 10 '14 at 14:26