RE: Scope problem
- To: mathgroup at smc.vnet.net
- Subject: [mg35985] RE: [mg35972] Scope problem
- From: "DrBob" <majort at cox-internet.com>
- Date: Sun, 11 Aug 2002 05:13:43 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
OK! I found I could add this statement after BeginPackage, rather than adding the other two contexts: PrependTo[$ContextPath, #] & /@ {"Statistics`Common`DistributionsCommon`", \ "Statistics`NormalDistribution`"} But, of course, it really should be BeginPackage["glibb`", {"Statistics`Common`DistributionsCommon`", \ "Statistics`NormalDistribution`"}] To find out where a set of functions are really coming from, you can load the packages you THINK they're in and then find out where they really are, like this: <<"Statistics`ContinuousDistributions`" <<"Graphics`Arrow`" Union[Context /@ {CDF, NormalDistribution, PDF, Arrow3D}] {"DrawGraphics`DrawingArrows`", "Statistics`Common`DistributionsCommon`", "Statistics`NormalDistribution`"} DrawGraphics was already loaded; I only THOUGHT it was in Graphics`Arrow`. Bobby Treat -----Original Message----- From: David Park [mailto:djmp at earthlink.net] To: mathgroup at smc.vnet.net Subject: [mg35985] RE: [mg35972] Scope problem Bobby, This is what I replied. _____________________________________ Try BeginPackage["`glibb`", {"Statistics`ContinuousDistributions`","Statistics`Common`DistributionsC ommo n`"} ] Then use can use the function CDF directly. This seems to be a common pitfall. Naming Statistics`ContinuousDistributions` in the BeginPackage statement is not sufficient, because it is actually an underlying package that exports CDF and other names. _________________________________________ But I winged it and testing now I found that I also needed to add BeginPackage["`glibb`", {"Statistics`ContinuousDistributions`","Statistics`Common`DistributionsC ommo n`","Statistics`NormalDistribution`"} ] If you name package XYZ in the BeginPackage statement, that does NOT make the names in any package that XYZ loads directly available to you the package writer. CDC is actually exported by Common`DistributionsCommon, and NormalDistribution is actually exported by NormalDistributions`. WRI does not exactly make that clear (especially NormalDistribution) and so people are always falling into this trap. There are some similar examples in the Units package. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: DrBob [mailto:majort at cox-internet.com] To: mathgroup at smc.vnet.net Aaron, When I add the line <<Statistics`ContinuousDistributions` directly after your BeginPackage statement, it works properly, but if I add the following line instead, it doesn't: Needs["Statistics`ContinuousDistributions`"] BeginPackage issues a Needs statement anyway (according to Help), but that doesn't seem to be good enough. Apparently you must load the package. I'm new to packages myself, so this totally mystifies me. Bobby -----Original Message----- From: Aaron [mailto:au198295 at hotmail.com] To: mathgroup at smc.vnet.net Subject: [mg35985] [mg35972] Scope problem I have been having difficulty using the distribution packages. In a package I created, I can't get the CDF function to evaluate, and I can't figure out the problem. Below I have included a very simple (and useless) package I created that runs in to the same problem. I want to use the numerical value of the CDF for a normal distribution. When I call TestFunction, this is the output: Global`glibb`Private`CDF[Global`glibb`Private`NormalDistribution[0, 1], -1] Global`glibb`Private`CDF[Global`glibb`Private`NormalDistribution[0., 1.], -1.] Calls to CDF return similar outputs in my useful packages. The package I am currently working with was originally written for Mathematica 2.0, and I am trying to update it to work with 4.0. I was told that all the functions were tested thoroughly in the 2.0 implementation and worked fine. TEST PACKAGE: file "glibb.m" ------------------------------------------------------------ BeginPackage["`glibb`", {"Statistics`ContinuousDistributions`"} ] glibb::usage = "glibb is a test package." TestFunction::usage = "TestFunction[]." Begin["`Private`"] TestFunction[] := Module[{alpha,alpha2}, alpha = CDF[NormalDistribution[0,1], -1]; Print[alpha]; alpha2 = N[CDF[NormalDistribution[0,1],-1]]; Print[alpha2]; ]; End[ ] EndPackage[ ] ------------------------------------------------------------- Thanks In Advance, Aaron