Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Afak10`Private`s + x^2

What if I define f[x] as:

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

The Output is:

Afak10`Private`asdfs$4980
share|improve this question
2  
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 at 9:34
    
Well its a big package with many functions, some of them are fine and others aren't –  user38032 Jan 25 at 16:02
1  
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 at 16:21
    
Take this library for example: –  user38032 Jan 25 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 at 22:01
show 4 more comments

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:

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:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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