MathGroup Archive 2005

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

Search the Archive

Re: Packages with Cyclic Dependencies

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63243] Re: [mg63219] Packages with Cyclic Dependencies
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Tue, 20 Dec 2005 04:19:44 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Catarina,

> Using Mathematica 5.1.
> 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?
> 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?

You can do this if you want, but if the two packages are so inter-twinned,
why not just put them both ni a single package?  In any case ...

Save this to one of the directories in your $Path (eg. $UserBaseDirectory <>
"/Applications") as ftna.nb

BeginPackage["ftna`", {"ftnb`"}]
ftna::usage = "ftna ...";
Begin["Private`"]
ftna[] := Print["Hi from ftn A"];
End[]
EndPackage[]

Now save this to ftnb.nb in the same directory.

BeginPackage["ftnb`", {"ftna`"}]
ftnb::usage = "ftnb ...";
Begin["Private`"]
ftnb[] := Print["Hi from ftn B"];
End[]
EndPackage[]

You can test that either package loads the other using the code below, which
should be saved to test.nb
Notebook[{
Cell[BoxData[{
    \(Off[General::spell, \ General::spell1]\), "\n", 
    \(Needs["\<ftna`\>"]\), "\n", 
    \(ftna[]\), "\n", 
    \(ftnb[]\)}], "Input"],

Cell[BoxData[
    \(Quit[]\)], "Input"],

Cell[BoxData[{
    \(Off[General::spell, \ 
      General::spell1]\), "\[IndentingNewLine]", 
    \(Needs["\<ftnb`\>"]\), "\n", 
    \(ftnb[]\), "\n", 
    \(ftna[]\)}], "Input"]
},
FrontEndVersion->"5.2 for Microsoft Windows",
ScreenRectangle->{{0, 1400}, {0, 974}},
WindowSize->{496, 740},
WindowMargins->{{448, Automatic}, {103, Automatic}}
]


It _is_ this way.  See a thread on this mailing list from a few weeks ago on
the merits of developing under the notebook interface verses developing
using an ASCII editor.

Regards,

Dave.


  • Prev by Date: Speeding up simple Mathematica expressions?
  • Next by Date: Expression timing; a black art?
  • Previous by thread: Re: Packages with Cyclic Dependencies
  • Next by thread: Re: Packages with Cyclic Dependencies