MathGroup Archive 2011

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

Search the Archive

Re: Odd (to me) Context issue with Packages?

  • To: mathgroup at
  • Subject: [mg115523] Re: Odd (to me) Context issue with Packages?
  • From: Jason Ledbetter <jasonbrent at>
  • Date: Thu, 13 Jan 2011 03:28:44 -0500 (EST)

I received a reply off-line that provided a resolution.

In summary, it seems that ToExpression is apparently running outside of the
BeginPackage/EndPackage defined Context and as a result the variables I'm
trying to reference (from String) via ToExpression are getting set in the
Global` context.

A potential workaround was: ToExpression["PackageName`Private`"~~variable]
vs. just ToExpression@variable

In making the suggested change, I was able to get this code (and my first
version which is worlds apart from the mess below) to work as I'd expected.

I'm not sure if this is a bug in/around ToExpression or not...


On Sun, Jan 9, 2011 at 2:20 AM, Jason Ledbetter <jasonbrent at>wrote:

> Folk,
> I have two (small, ~20KB and ~17KB) notebooks at the following URIs that
> are
> working demonstrate my current Mathematica 8 frustrations.
> 1)<>
> This notebook is the same code from the next example with a package and
> exported function wrapper around in. In this example, there are two input
> cells that need to be executed in order for the failure to appear.
> After "genInfo2[]" is executed in the second cell, a simple manipulate
> appears and both of the functions Covariance and Correlation fail because
> some of the variables are apparently in a different Context than I expect.
> e.g., they "cpu" variable that is shown in the output cell from the
> Manipulate appears to be in Global` instead of Huh`Private` as I'd expect.
> There *IS* a Huh`Private`cpu variable that gets created here, but
> apparently
> it isn't what is getting passed through the Manipulate and into the
> Covariance and Correlation functions.
> (Execute Remove["Huh`*"] to clean up what this adds to your M environment)
> 2)<>
> This is the same code as in demo_fail2.nb, but without the package wrapper
> around it. THIS code works exactly as I'm expecting.
> I've been beating my head against #1 for too many hours now.
> Can someone shed some light into what is going on here and how to fix this
> apparent context failure?
> Note: If you execute demo_fail.nb before demo_fail2.nb, the failure will
> not
> occur. This appears to be because demo_fail2.nb's requirements are
> satisfied
> by variables in Global` context at that point.
> -jbl

  • Prev by Date: Re: question on diophantine equations in Mathematica
  • Next by Date: Is ListVectorPlot broken in Mathematica 7?
  • Previous by thread: Re: Units question
  • Next by thread: how to remove $RecursionLimit::reclim: and $IterationLimit::itlim: