Nested Packages and scoping
- To: mathgroup at smc.vnet.net
- Subject: [mg63785] Nested Packages and scoping
- From: Detlef Müller <dmueller at mathematik.uni-kassel.de>
- Date: Sat, 14 Jan 2006 02:32:32 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hello, I wrote two Packages, the one, say "A" containing Basics, and one, say "B" containing higher Functions, using those of "A". Now the User should type Needs["B`"] and have all the Functions of A and B. I figured out, that for this following looks awkward, but seems the only way: --------------------- File A.m BeginPackage["A`"]; f::usage="f is 7"; Begin["`Private`"]; f:=7; End[] EndPackage[] --------------------- File B3.m: Needs["A`"]; (* without this, f not known in calling context *) BeginPackage["B3`"]; Needs["A`"]; (* without this, f not known in this context *) Print[f]; EndPackage[] ---------------------- But then I had to nest it one Step further. And now a problem occures: If I have a package X.m with g::usage = "g is 5"; BeginPackage["X`"]; g := 5; EndPackage[] And A.m is switched to ------------------------- Needs["X`"]; BeginPackage["A`"]; Needs["X`"]; f::usage = "f is 7"; Begin["`Private`"]; f := 7; End[] EndPackage[] ------------------------- The following happens: Needs["B3`"] (g::"shdw"\),Symbol g appears in multiple contexts (X`,Global`) definitions in context (X`) may shadow or be shadowed by other \ definitions. mehr... {f, g} {7, g} Is there a Way to achieve, that the Symbols of all used Packages are inherited? (Version is Mathematica 5.1) Greetings, Detlef