MathGroup Archive 2009

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

Search the Archive

Re: Share symbols among packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97379] Re: Share symbols among packages
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 12 Mar 2009 02:18:07 -0500 (EST)
  • References: <gp82if$2l4$1@smc.vnet.net>

Andrey wrote:
> Hello group,
> 
> How to use Global symbols in several user packages?
> 
> That is, I have:
> 
> BeginPackage["MyPack1`"]
> 
> myVar::usage="My var";
> 
> myFun1::usage="My fun1";
> 
> Begin["`Private`"];
> ...
> (* use myVar *)
> ...
> End[]
> EndPackage[]
> 
> BeginPackage["MyPack2`"]
> 
> myVar::usage="My var";
> 
> myFun2::usage="My fun2";
> 
> Begin["`Private`"];
> ...
> (* use myVar *)
> ...
> End[]
> EndPackage[]
> 
> And then I would like to do like this:
> 
> myVar=data; myFun1[a,b,c]
> myVar=data; myFun2[a,b,c]
> 
> The problem is:
> 
> myVar::shdw: "Symbol myVar appears in multiple contexts \!\({\"MyPack1`
> \", \"MyPack2`\"}\); definitions in context \!\(\"MyPack2`\"\) may
> shadow or be shadowed by other definitions."
> 
> Any ideas?
> 
> 
> Regards,
> 
> -Andrey
> 
You have not been totally clear as to whether these are your packages - 
which you can alter. If they are, the simplest solution is to name the 
exported symbols differently in the two packages! However, you can 
access any symbol - even a 'Private' symbol - by using its full name. 
Thus MyPack1 could access MyPack2`Private`privatefunc2 just by using the 
fully specifies name. This function could also be accessed from the 
Global` context in the same way.

This can often be useful while debugging a package - because you can 
actually view variables that are internal to the package.

I am not sure if this answers your question!

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: about mathlink connection
  • Next by Date: Re: Share symbols among packages
  • Previous by thread: Re: Share symbols among packages
  • Next by thread: Re: Share symbols among packages