MathGroup Archive 2005

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

Search the Archive

Re: Packages with Cyclic Dependencies

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63235] Re: Packages with Cyclic Dependencies
  • From: albert <awnl at arcor.de>
  • Date: Tue, 20 Dec 2005 04:19:32 -0500 (EST)
  • References: <do68ah$b25$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

> I have two packages, let's call them A and B and they both need each
> other, something like:
> A.m:
> BeginPackage["A`"]
> Needs["B`"]
> 
> ...
> 
> EndPackage[]
> 
> B.m:
> BeginPackage["B`"]
> Needs["A`"]
> 
> ...
> 
> EndPackage[]
> 
> Can I have this kind of cyclic package dependency?

Yes you can, since Needs only reads the file once and in later calls only
will arrange Context and ContextPath you won't see any problems with
recursion when loading. But be aware that there still might be problems
because symbols might not be defined in the Context you expect them to be
if you are not careful. Basically everything should work fine if you first
mention the symbols (usually by defining a usage message) you want to
export from each package and only after that load the other package with
Needs. Still it might be a better idea to use a third package C` that
definies all commonly used symbols/functions and only load C` in both A`
and B` and avoid the recursion altogether, if that's possible in your case.

> Now, my current package design is, I write the packages in a notebook
> and mathematica seems to create the .m automagically. Should this be
> this way? I never get to touch the .m?

That is a very common way and comfortable way to create package files. You
don't need to ever look at the .m files, if you don't want to. You can read
and edit these automatically generated package files as textfiles, but that
is often no pleasure, so if you prefer to work with pure textfiles, you
probably want to start off with a texteditor right from the beginning...
 
hth.

albert


  • Prev by Date: Re: Output a list of keywords
  • Next by Date: Re: Re: Cross results?
  • Previous by thread: Packages with Cyclic Dependencies
  • Next by thread: Re: Packages with Cyclic Dependencies