Pacakges that need packages that need packages
- To: mathgroup at smc.vnet.net
- Subject: [mg37771] Pacakges that need packages that need packages
- From: "Steven T. Hatton" <hattons at globalsymmetry.com>
- Date: Tue, 12 Nov 2002 03:13:30 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I'm trying to use a package I created from another package I'm writing. I'm
finding the context issues less than obvious. To give an example:
I create 3 files:
TestPackage3.m
BeginPackage["GS`TestPackage3`","GS`TestPackage4`","CSM`Classes`"]
myFunction2::usage="myFunction2[message] echos message, and prints context \
information."
myFunction3::usage="myFunction3[] echos myFunction3..., ."
myObj::usage="new[myObj,myParam] creates a new object"
myMethod::usage="myMethod[objName, string] prints string and myVar."
Begin["`Private`"]
myFunction2=Function[{message},
Print[message];
Print["$Packages: "<>$Packages];
Print["$ContextPath: "<>$ContextPath];
Print["Context[message]: "<>Context[message]]]
myFunction3=Function[{},myFunction["myFunction3..."]];
Class[myObj,Object,{myVar},
{
{new,Function[{myParam},
new[super];
myVar=myParam]},
{myMethod,Function[{myMessage},
Print["My Message: "<> myMessage];
Print["My Variable: "<>myVar]
]}}]
$ContextPath
Print["$ContextPath from GS`TestPackage3`Private` "<>$ContextPath];
End[]
EndPackage[]
TestPackage4.m
BeginPackage["GS`TestPackage4`", "CSM`Classes`"]
myFunction::usage = "myFunction[message] echos message, and prints context \
information."
Begin["`Private`"]
myFunction = Function[{message},
Print[message];
Print["$Packages: " <> $Packages];
Print["$ContextPath: " <> $ContextPath];
Print["Context[message]: " <> $ContextPath];
Print["Context[]: " <> $ContextPath]
]
End[]
EndPackage[]
runTest.m
AppendTo[$Path,ToFileName[ParentDirectory[]]]
Needs["CSM`Classes`"]
Needs["GS`TestPackage3`"]
Needs["GS`TestPackage4`"]
obj = new[myObj, "parameter name"]
$ContextPath
$Context
Names["Global`*"]
FullForm[obj]
mesg = "This is a message";
myMethod[obj, mesg]
The only way I can make this work is to explicitly name CSM`Classes` in the
'Needs' list of BeginPackage in TestPackage3. Note that it is in the 'Needs'
list of TestPackage4, and that is in the 'Needs' list of TestPackage3
already. I also loaded it into my context before I did anything else.
If I don't have CSM`Classes` explicitly listed in the BeginPackage of
TestPackage3, I get this for the context:
$ContextPath from GS`TestPackage3`Private`\
GS`TestPackage3`GS`TestPackage4`System`
If it is present, I get this:
$ContextPath from GS`TestPackage3`Private`\
GS`TestPackage3`GS`TestPackage4`CSM`Classes`System`
This seems like a method of adding new applications which will not scale very
nicely. Is there a better way to accomplish this?
--
STH
Hatton's Law:
"There is only One inviolable Law."