# Mathematica Library

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:

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[]


Output:

Afak10Privates + x^2


What if I define f[x] as:

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


The Output is:

Afak10Privateasdfs\$4980

-
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. – Mr.Wizard Jan 25 '14 at 9:34
Well its a big package with many functions, some of them are fine and others aren't – user38032 Jan 25 '14 at 16:02
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. – bill s Jan 25 '14 at 16:21
Take this library for example: – user38032 Jan 25 '14 at 22:00
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[] – user38032 Jan 25 '14 at 22:01

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 Afak10Private 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 + Globals];  (* as part of your package *)


Now using the function:

f[z]

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:

-