I created a Mathematica packagr and then I used the Needs function to add the library to my .nb file, but when use a function in my .nb file and the function is built in my library it comes up with the functions output multiplied by "mylibrarynamePrivate".

My Package:

Unprotect @@ Names["Afak10`*"]; 
ClearAll @@ Names["Afak10`*"]; 
f::usage = "f[x]" 
f[x_] := Module[{}, x^2 + s]; 
Protect @@ Names["Afak10`*"]; 


Afak10`Private`s + x^2

What if I define f[x] as:

f[x_] := Module[{asdfs},asdfs];

The Output is:

  • 2
    $\begingroup$ You need to give a more concrete example of your functions and how you are using them. I can think of a few different possible causes for this but I don't feel like explaining problems that don't exist. $\endgroup$
    – Mr.Wizard
    Jan 25, 2014 at 9:34
  • $\begingroup$ Well its a big package with many functions, some of them are fine and others aren't $\endgroup$
    – user38032
    Jan 25, 2014 at 16:02
  • 1
    $\begingroup$ If you want help, then find a simple case: make up a small package that has the same problem. Then we can try and help. $\endgroup$
    – bill s
    Jan 25, 2014 at 16:21
  • $\begingroup$ Take this library for example: $\endgroup$
    – user38032
    Jan 25, 2014 at 22:00
  • $\begingroup$ BeginPackage["Afak10"] Unprotect @@ Names["Afak10*"]; ClearAll @@ Names["Afak10*"]; f::usage = "f[x]" Begin["Private"] f[x_] := Module[{}, x^2 + s]; End[] Protect @@ Names["Afak10*"]; EndPackage[] $\endgroup$
    – user38032
    Jan 25, 2014 at 22:01

1 Answer 1


In your code you have a Symbol s that is not declared before the line Begin line. Because of this it is created in that specified Afak10`Private` context. (Also, your code presently has an error; it needs to be Begin["Private`"].) You can include the Global` context if that is in fact the Symbol you wish to return:

f[x_] := Module[{}, x^2 + Global`s];  (* as part of your package *)

Now using the function:

s + z^2

Nevertheless I caution you about this method as you generally should not use (plain) global Symbols like this; instead use Formal Symbols which are Protected to prevent accidental assignment.

f[x_] := Module[{}, x^2 + \[FormalS]];

It looks like this:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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