Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Loading packages within packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30295] Re: Loading packages within packages
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sun, 5 Aug 2001 16:18:39 -0400 (EDT)
  • References: <9kdbv0$f4u$1@smc.vnet.net> <9ki2p7$kde$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Oliver,

First the explanation then the solution,

EXPLANATION

Note that in the package Statistics`NormalDistribution` we have

BeginPackage["Statistics`NormalDistribution`",
             "Statistics`DescriptiveStatistics`",
      "Statistics`Common`DistributionsCommon`"]

and after

<<Statistics`NormalDistribution`

we get

Context[PDF]

        Statistics`Common`DistributionsCommon`

So PDF comes from loading the package Statistics`Common`DistributionsCommon`
as helper package.


However in your package  TzmSignalTheory when the line

BeginPackage["TzmSignalTheory`",{"Statistics`NormalDistribution`"}]

is loaded, although the packages   "Statistics`DescriptiveStatistics`" ,
"Statistics`Common`DistributionsCommon`" are loaded as helpers for
"Statistics`NormalDistribution`"  the final result is that the *only*
contexts that are added to are "TzmSignalTheory`" and
"Statistics`NormalDistribution`"  --- so "Statistics`DescriptiveStatistics`"
, "Statistics`Common`DistributionsCommon`"  are not active ( I know that
this seems odd, but that's the way it is).

This means that when the line

DiscreteGaussExcitement[f_,width_,var_:w]:=
PDF[NormalDistribution[f,width],var]

is evaluated,  Statistics`Common`DistributionsCommon` is not found and  PDF
is translated as TzmSignalTheory`Private`PDF.

This is what you are seeing.

SOLUTION:

Modify your package line  BeginPackage[...] to
        BeginPackage["TzmSignalTheory`",
                {"Statistics`NormalDistribution`",
"Statistics`DescriptiveStatistics`",
                  "Statistics`Common`DistributionsCommon`"}
        ]


( you can miss out the list brackets if you want)

Now we get

<<TzmSignalTheory`

DiscreteGaussExcitement[a,b,c]

1/(E^((-a + c)^2/(2*b^2))*(b*Sqrt[2*Pi]))


--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Oliver Friedrich" <oli.fri at gmx.de> wrote in message
news:9ki2p7$kde$1 at smc.vnet.net...
> Hallo again,
>
> thanks for your help, my second question (how to write and save a
package?)
> seems to be answered.
> But there is still my problem with the unevaluated ExternalFunction A.
> My abstract MyPackage package doesn't seem to reflect the error that I
made,
> because none of you experts did find anything. So I give a real example
(and
> that is almost the thing my packet should do, even the names).
>
> BeginPackage["TzmSignalTheory`",{"Statistics`NormalDistribution`"}]
>
> DiscreteGaussExcitement::usage:=
> "blabla"
>
> Begin["`Private`"]
>
> DiscreteGaussExcitement[f_,width_,var_:w]:=
> PDF[NormalDistribution[f,width],var]]
>
> End[]
>
> EndPackage[]
>
> So, that's my pain in the neck. If I call this package in application.nb I
> get
>
> In[1]=
> <<TzmSignalTheory`
>
> In[2]=
> DiscreteGaussExcitement[a,b,c]
>
> Out[2]=
> TzmSignalTheory`Private`PDF[NormalDistribution[a,b],c]
>
> Why doesn't it find the definitions for PDF and NormalDistribution ? They
> sure are in this package Statistics`NormalDistribution`, cause it works
when
> I load that package in application.nb and work directly with PDF and
Norm...
>
> My second thought was: OK, can't work if PDF appears in
> TzmSignalTheory`context(whatever the reason, it does at all) so my second
> approach was
>
> BeginPackage["TzmSignalTheory`",{"Statistics`NormalDistribution`"}]
>
> DiscreteGaussExcitement::usage:=
> "blabla"
>
> Begin["`Private`"]
>
> DiscreteGaussExcitement[f_,width_,var_:w]:=
>
Statistics`NormalDistribution`PDF[Statistics`NormalDistribution`NormalDistri
> bution[f,width],var]]
>
> End[]
>
> EndPackage[]
>
> When I load this package (after quit the kernel and reload, I'm really
> carefully with that topic), the following happens:
>
>
> In[1]=
> <<TzmSignalTheory`
>
> PDF::"shdw":
>     "Symbol \!\(\"PDF\"\) appears in multiple contexts \
> \!\({\"Statistics`NormalDistribution`\", \(\"St\" \\[Ellipsis]
\"on`\"\)}\);
> \
> definitions in context \!\(\"Statistics`NormalDistribution`\"\) may shadow
> or \
> be shadowed by other definitions."
>
> In[2]=
> DiscreteGaussExcitement[a,b,c]
>
> Out[2]=
> PDF[NormalDistribution[a,b],c]
>
> First that warning after loading the package, but the line Out[2] looks
> nicer to me, but still it is unevaluated, Mathematica can't find that
> bleeding definitions.
> But if I load the Statistics`NormalDistribution`into my application.nb...
>
>
> DiscreteGaussExcitement[a,b,c]
>
> \!\(E\^\(-\(\((\(-a\) + c)\)\^2\/\(2\ b\^2\)\)\)\/\(b\ \@\(2\ \[Pi]\)\)\)
>
> Now it comes along with the correct answer. Loading my Statistics into
> application.nb could be a workaround, but that's an awful solution.
>
> By the way: Thanks for the advice with that AutogeneratedPackage option.
But
> to me it wasn't easy to find. It isn't documented in the online help, is
it?
>
> Oliver
>
>




  • Prev by Date: Re: Partial fraction expansion
  • Next by Date: Adding text at various X,Y locations on Multi-Function Graphs
  • Previous by thread: RE: Re: Loading packages within packages
  • Next by thread: Trouble with Mathematica 4.1 after uninstalling Mathematica 3.0