MathGroup Archive 2004

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

Search the Archive

Re: Package dependencies

  • To: mathgroup at
  • Subject: [mg45753] Re: [mg45688] Package dependencies
  • From: Omega Consulting <info at>
  • Date: Fri, 23 Jan 2004 03:15:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On a modern computer, package loading is quick. Unless the package is very 
large (or part of a large set of interdependent packages), DeclarePackage 
is not really necessary. Just use Get or Needs in c.m.

However, if you must load the packages when f is first used, you can create 
a "stub" function. Something like:

f := (

In[1]:= << c`

f := (Clear[f]; << a`; Needs[b`]; f)

So f is defined to load a` and b`, which re-defines f.

In[3]:= f[1]
Out[3]= 1

f[0] = 0
f[1] = 1

At 04:07 AM 1/20/2004, Maxim wrote:
>Suppose we have a package a.m defining function f:
>f[0] = 0
>Then we create package b.m which introduces additional definitions for
>f[1] = f[0] + 1
>Now after loading b.m we'll have f[0]=0 and f[1]=1. Finally, we want to
>create a package c.m that determines when b.m should be autoloaded. We
>add the following line to c.m:
>Unfortunately, it doesn't work that way:
>(standalone kernel will also give f::shdw warning). The reason is that
>DeclarePackage creates symbol f (with attribute Stub) in the b` context.
>This implementation decision seems rather questionable: the idea of
>DeclarePackage is to load b.m when f is first used, which is exactly
>what we want here -- but nobody said the symbol f was needed in context
>Probably this difficulty can be avoided by some creative usage of Remove
>and $NewSymbol, but simply adding Remove["b`f"] to b.m won't solve the
>problem completely.
>This is exactly the situation with Geometry\Polytopes.m,
>Graphics\Polyhedra.m and Graphics\Kernel\init.m -- you can use
><<graphics` to declare most of the symbols in all the Graphics\*
>packages, but not Tetrahedron, Cube and others because there are
>definitions for them both in Polytopes.m and Polyhedra.m.
>Maxim Rytin
>m.r at

Omega Consulting
"The final answer to your Mathematica needs"

  • Prev by Date: Re: Tail recursion and local functions
  • Next by Date: Re: Trivial Fourier Transform Question
  • Previous by thread: Package dependencies
  • Next by thread: Re: Package dependencies