Re: Loading packages within packages

*To*: mathgroup at smc.vnet.net*Subject*: [mg30293] Re: Loading packages within packages*From*: Tom Burton <tburton at cts.com>*Date*: Sun, 5 Aug 2001 16:18:37 -0400 (EDT)*References*: <9kdbv0$f4u$1@smc.vnet.net> <9ki2p7$kde$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hello, On Sun, 5 Aug 2001 00:08:07 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote: ... BeginPackage["TzmSignalTheory`",{"Statistics`NormalDistribution`"}] ... DiscreteGaussExcitement[f_,width_,var_:w]:= PDF[NormalDistribution[f,width],var]] ... <End package, etc.> -------------- To get the statement above to work properly, I modified it as follows: DiscreteGaussExcitement[f_,width_,var_:w]:= Statistics`Common`DistributionsCommon`PDF[ Evaluate[NormalDistribution[f,width]],var] So, rather than let the symbol PDF take on the context of your package, I forced it to take on the context it is supposed to have. (You can find out what context it is supposed to have with Context[PDF} after loading directly the Statistics`NormalDistribution` package.) Another, and I think better, way to correct the problem is to include the context the PDF in your package declaration: BeginPackage["TzmSignalTheory`",{"Statistics`NormalDistribution`", "Statistics`Common`DistributionsCommon`"}] So why would this specification of context be needed? I think the reason is that package inclusion through BeginPackage is not recursive. If package A needs package B, which in turn needs C, then write BeginPackage[A,{B,C}]. (See The Mathematic Book 2.6.10.) Once you realize what is going on, you can find the following text in the help for Statistics`Common`: "The Statistics`Common` subdirectory includes several packages that are used by the primary Statistics packages to share common symbols. These common packages are not meant to be loaded individually. Most users do not need to be aware of them, but if you are writing your own packages using functions defined by a Statistics package, it is wise to check whether symbols you need are introduced via one of the Common packages." But if you don't know about Statistics`Common`, then how would you know to look here? I didn't. That's why checking the context of the offending symbols is a good idea. Tom Burton