MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Two different packages can not Need[] the same

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79896] RE: [mg79867] Two different packages can not Need[] the same
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Wed, 8 Aug 2007 04:51:35 -0400 (EDT)
  • References: <200708070532.BAA12076@smc.vnet.net>

Hi Benedek,

> Here is a problem a I face with:
> I define two packages. Both needs the same 
> Statistics`ContinuousDistibutions` package. However, the 
> second one can not use it. Why? And how to resolve this problem?
> 
> To make it more exact, in the following example I will define two
> packages: ff and gg with the corresponding f and g functions 
> both using NormalDistribution. The first one evaluated works 
> while the second does not. the problem is even more 
> disappointing if we Get[] one packege twice and then are 
> unable to use the function. More complicated verisions can 
> appear using the Sytem` functions or using built-in packages 
> where we does not even know what other packages are invited.
> 
> Does anyone have a solution for this problem?
> 
> Kind Regards
> Bence

The In[] & Out[]'s here are very unhelpful ....  

> In[1]:=BeginPackage["ff`"]
> Out[1]=ff`
> In[2]:=Unprotect[f]
> Out[2]={}
> In[3]:=Begin["`Private`"]
> Out[3]=ff`Private`
> In[4]:=Needs["Statistics`ContinuousDistributions`"]
> In[5]:=Options[f]:={MyDistributionFunction\[Rule](NormalDistri
> bution[#,
> 0.2 #]&)}
> f[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]]
> In[7]:=End[]
> Out[7]=ff`Private`
> In[8]:=Protect[f]
> Out[8]={f}
> In[9]:=EndPackage[]
> 
> In[10]:=f[3]
> Out[10]=2.16487
> In[11]:=ff`f[3]
> Out[11]=4.16217
> 
> In[12]:=BeginPackage["gg`"]
> Out[12]=gg`
> In[13]:=Unprotect[g]
> Out[13]={}
> In[14]:=Begin["`Private`"]
> Out[14]=gg`Private`
> In[15]:=Needs["Statistics`ContinuousDistributions`"]
> In[16]:=Options[g]:={MyDistributionFunction\[Rule]
> (NormalDistribution[#,0.2 #]&)}
> g[x_,opts___]:=Random[(MyDistributionFunction/.{opts}/.Options[f])[x]]
> In[18]:=End[]
> Out[18]=gg`Private`
> In[19]:=Protect[g]
> Out[19]={g}
> In[20]:=EndPackage[]

You have a typo.  You meant Options[g] rather than Options[f] in your
definition of g.

Also note that you don't need either of the two Needs[] statements.  As
online help shows, defining your packages

	BeginPackage["ff`", {"Statistics`ContinuousDistributions`"}]
	BeginPackage["gg`", {"Statistics`ContinuousDistributions`"}]

Does the same thing.

Regards,

Dave.


  • Prev by Date: Re: forming continuous "trail" with Locator
  • Next by Date: Re: Beta function, Integral
  • Previous by thread: Two different packages can not Need[] the same utility package?
  • Next by thread: Re: Two different packages can not Need[] the same utility