MathGroup Archive 2002

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

Search the Archive

Re: Pacakges that need packages that need packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37829] Re: Pacakges that need packages that need packages
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 14 Nov 2002 06:11:40 -0500 (EST)
  • References: <aqqdp1$sfb$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Steven,

If a symbol in your code comes from another package, say needed.m, then that
package must be listed as a needed package in the first line of your code,
thus:
        BeginPackage["mypacks`test`", "needed`", ....]
It is not enough that it be a needed package of a package that you have
listed in BeginPackag[...]
(at least this is so unless you use "hidden" importation by Needs[..] in
later lines).

The problem is dealt with in Help>HelpBrowser>Add-ons>Standard
Packages>Appendix:  Basing New Packages on the Standard Mathematica
PackagesPackages (thought this should be "on other packages").

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Steven T. Hatton" <hattons at globalsymmetry.com> wrote in message
news:aqqdp1$sfb$1 at smc.vnet.net...
> 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."
>
>




  • Prev by Date: Re: Idempotence
  • Next by Date: Re: PolarPlot problem
  • Previous by thread: Re: Pacakges that need packages that need packages
  • Next by thread: Improper integral