Re: Shadowing of symbols in a package
- To: mathgroup at smc.vnet.net
- Subject: [mg61253] Re: Shadowing of symbols in a package
- From: albert <awnl at arcor.de>
- Date: Fri, 14 Oct 2005 05:53:40 -0400 (EDT)
- References: <dikta4$4ue$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Hannes, > --> The following warning is generated by running the notebook: > > Meter::shdw: Symbol Meter appears in multiple contexts {PackageUnits`, > Miscellaneous`SIUnits`}; definitions in context PackageUnits` may > shadow or be shadowed by other definitions. > ... > Should I ignore the warning, or does it indicate that something should > be done better? If you write packages intended for others to use you should never ignore shadow messages. In this case the reason for the message is as follows: Miscellaneous`Units` automatically loads Miscellaneous`SIUnits` and puts it onto the context path _and_ Meter happens to be in the SIUnits-Package: In[1]:= Needs["Miscellaneous`Units`"] In[2]:= Context[Meter] Out[2]= Miscellaneous`SIUnits` In[3]:= $ContextPath Out[3]= {Miscellaneous`Units`, Miscellaneous`SIUnits`, Global`, System`} For reasons I don't know and understand, using package names as second arguments in BeginPackage shows a slightly different behaviour: In[1]:= BeginPackage["test`",{"Miscellaneous`Units`"}] Out[1]= test` In[2]:= $ContextPath Out[2]= {test`, Miscellaneous`Units`, System`} In[3]:= Context[Meter] Meter::shdw: Symbol Meter appears in multiple contexts {test`, Miscellaneous`SIUnits`}; definitions in context test` may shadow or be shadowed by other definitions. Out[3]= test` In[4]:= EndPackage[] So what you can learn is that the Meter you see in your output is not the Meter you intend to use and it will fail to be correctly treated by the Units`-Functions. The workaround in this case is to also add the Context Miscellaneous`SIUnits` to your BeginPackage-Statement: In[1]:= BeginPackage["test`" {"Miscellaneous`Units`","Miscellaneous`SIUnits`"}] Out[1]= test` In[2]:= $ContextPath Out[2]= {test`, Miscellaneous`Units`, Miscellaneous`SIUnits`, System`} In[3]:= Context[Meter] Out[3]= Miscellaneous`SIUnits` In[4]:= EndPackage[] No error message, the correct Meter is used. Anyway it is counterintuitiv that in this case the behaviour of BeginPackage is so different from what Needs does, but most probably everything works as specified :-). cheers, albert