Second argument of BeginPackage, revisited
- To: mathgroup at smc.vnet.net
- Subject: [mg78295] Second argument of BeginPackage, revisited
- From: "Andrew Moylan" <andrew.j.moylan at gmail.com>
- Date: Wed, 27 Jun 2007 05:42:01 -0400 (EDT)
Unfortunately (in my opinion), BeginPackage["a`", {"b`"}] does not *quite* call Needs[] on its second argument(s). Suppose b.m looks like this: BeginPackage["b`", {"PhysicalConstants`"}] (* some code *) EndPackage[] Then calling Needs["b`"] in a new kernel results in "PhysicalConstants`" being on the list of contexts, so that e.g. SpeedOfLight works as expected. But calling BeginPackage["a`", {"b`"}] instead does *not* put PhysicalConstants on the list of contexts during the definition of the package, so that e.g. SpeedOfLight results in the creation of a new, useless symbol called a`SpeedOfLight. Finally, for maximum confusion (in my opinion), once EndPackage[] is called to finish loading the "a`" package, "PhysicalConstants`" *is* placed on the list of contexts, causing shadowing between a`SpeedOfLight and PhysicalConstants`SpeedOfLight. Effectively, BeginPackage appears to 1. Call Needs[] on its second arguments, then 2. Temporarily remove from the context path any extra contexts those packages added to the context path, then finally 3. Put all those temporarily removed packages back onto the context path once EndPackage[] is called. Can anyone help me understand why this behaviour is useful?