MathGroup Archive 2002

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

Search the Archive

Re: Package function variable hiding.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38521] Re: [mg38503] Package function variable hiding.
  • From: Omega Consulting <info at omegaconsultinggroup.com>
  • Date: Fri, 20 Dec 2002 23:40:36 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 03:27 AM 12/20/2002, Nigel King wrote:
>In the following minimised package func does not do what I want. I want
>'test' to "see" NoncentralChiSquareDistribution. Instead it creates a
>'Private' version. What am I doing wrong?
>
>In[1]:= BeginPackage["test`", "Statistics`ContinuousDistributions`"]; In[
>2]:= Needs["Statistics`ContinuousDistributions`"]; In[3]:= func::usage :
>= "func[k] a useful function" In[4]:= Begin["`Private`"]; In[5]:=
>\!\(\(
>func[mask_?NumericQ] :=
>       10  Log[10,
>           Quantile[
>
>NoncentralChiSquareDistribution[2,
>               2\ 10\^\((\((30 - mask)\)/
>20)\)], 0.0001]];\)\) In[6]:= End[]; In[7]:= EndPackage[]; In[8]:= func[
>10] Out[8]=
>\!\(\(\(1\/Log[10]\)\((10\ Log[
>
>test`Private`Quantile[NoncentralChiSquareDistribution[2, 20],
>
>0.0001`]])\)\)\) In[9]:= Context[NoncentralChiSquareDistribution] Out[9]
>=
>"Statistics`ContinuousDistributions`"
>
>TIA
>---
>Nigel King

This is an age-old context issue. When you declare auxiliary contexts 
through BeginPackage it does 2 things:

1) Load the package for that context. In this case, that package also loads 
secondary packages.
2) Add the context to the $ContextPath. This makes any symbol in that 
context available within your package. It does not add the contexts of the 
secondary packages. If you need to use symbols from these packages, their 
context must be added to BeginPackage.

So, given:

In[1]:=Needs["Statistics`ContinuousDistributions`"]

In[2]:=Context[NoncentralChiSquareDistribution]
Out[2]=Statistics`ContinuousDistributions`

In[3]:=Context[Quantile]
Out[3]=Statistics`DescriptiveStatistics`

Your package should start with

BeginPackage["test`", {"Statistics`ContinuousDistributions`", 
"Statistics`DescriptiveStatistics`"}]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com



  • Prev by Date: RE: Nonparametric kernel density estimators
  • Next by Date: Re: portable issues with zip files
  • Previous by thread: Package function variable hiding.
  • Next by thread: Cox partial likelihood function, how to solve?