If I use Subbu instead of Private in your use-case1 code.still it's working,then what's the use of Private. as for my understanding,Private functions are not accessible from another Packages.But here If you call any private functions with full contexts in any another package.It's working fine. That means,we can't write the Private functions inMM.
–
subbuApr 30 '13 at 11:50

2

@subbu there is nothing special about Private as a context name; it is merely convention. Also, "private" doesn't mean cannot be read, it just means "should not conflict (collide) with." Are you trying to keep people from reading a function definition? You should look at ReadProtected and Locked (attributes) if that is the case. Please consider posting a new question describing what you want out of a "private" function if not.
–
Mr.Wizard♦Apr 30 '13 at 11:53

If you insist to write code this way I think you should really try to understand what $ContextPath and $Context do and how BeginPackage,EndPackage, Begin and End control these.

As Mr. Wizard has explained the problem you are facing is that within the private part of the package Test1` is in $ContextPath, but not Test1`Private`. If neither Test1`function1 nor Test1`Private`function1 exist, no function1 can be found in $ContextPath and a new symbol is generated using the current value of $Context which is Test1`Private`. After an explicit call to Test1`function1 that symbol exists. When you load the package code after Test1`function1 exists, it will be found in $ContextPath and will be used for the definition in the private part and no private symbol Test`Private`function1 will be used or generated.

The following will put the private context which $Context points to before everything else in $ContextPath, so now the definition will be made to the private symbol even if the public symbol exists. This should solve your problem and doesn't need to make any changes to other symbols, whether they exist or not:

You should be aware that such manual manipulations of $ContextPath might have unexpected side effects, so it should be used with some care. Considering this, it probably would be a good idea to explain more clearly what you try to achieve, my impression is that you are probably abusing the namespace functionality for something that probably could be achieved better with other means.

Really,I am not understood,what you are writing . why you are using ClearAll[function1]; function1::usage = "test";.I evaluated your code,your code is working quietly opposite to my requirements. Actually,we are defining the function as a Private but your code returns like in the following way 5 Test1Privatefunction1[5]
–
subbuApr 30 '13 at 11:08

No, you need to use Remove[function1];
–
Chris DegnenApr 30 '13 at 11:10

@ChrisDegnen where will I use Remove[function1]; code.
–
subbuApr 30 '13 at 11:15

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.