MathGroup Archive 1996

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

Search the Archive

Re: packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3631] Re: packages
  • From: ianc (Ian Collier)
  • Date: Sat, 30 Mar 1996 02:47:16 -0500
  • Organization: Wolfram Research, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4j7hn3$af4 at dragonfly.wolfram.com>, rhall2 at umbc.edu (hall
robert) wrote:

> I'm having a problem loading packages. I'm using Mathematica 
> 2.2.2 on a Mac 7100/66. The standard packages load fine. I copied 
> the ComplexMap2 package from Maeder, "Programming in Mathematica,"
> p. 15. I've been over the code line by line, and as near as I can 
> tell, I haven't made any mistakes in copying, but it won't load.
> 
> In[5]:=
>         Needs[ "ComplexMap`" ]
> 
>         Get::noopen: Can't open ComplexMap.m.
>         Needs::nocont: 
>                 Warning:Context ComplexMap`
>                                 was not created when Needs was evaluated.
> Out[5]=
>         $Failed
> 
> The following doesn't give me any warnings, but it doesn't load the package 
> either.
> 
> In[3]:=
>         <<ComplexMap2.m
> In[5]:=
>         $ContextPath
> Out[5]=
>         {Global`, System`}
> 
> The functions I want to access work fine if I copy them directly into
> my current notebook.
> 
> As near as I can tell, the standard packages and the ComplexMap 
> package have the same structure and use the same commands. Can 
> anyone explain why the ComplexMap package doesn't load?
> 
> If you don't have the book handy, here's the relevant parts
> of the package:
> 
> BeginPackage[ "ComplexMap`" ]
> 
> CartesianMap::usage = "[description deleted]"
> 
> PolarMap::usage = "[description deleted]"
> 
> Begin[ "`Private`" ]
> 
>         [Functions deleted. They work outside of the package, so
>                 I'm assuming they're not the problem.]
> 
> End[ ]
> 
> EndPackage[ ]
> -- 


There are two problems here.

The first is that the problem is that the directory containing the 
ComplexMap pack package (Mathematica/Packages/ProgrammingExamples) 
is not by default on the Mathematica search path. The 
Mathematica/Packages directory is on the search path so you can 
load the package using

    <<ProgrammingExamples`ComplexMap`

If you use Needs to load the package, however, you will still get 
a warning:

In[1]:=
    Needs[ "ProgrammingExamples`ComplexMap`"]

    Needs::nocont: 
       Warning:Context ProgrammingExamples`ComplexMap`
         was not created when Needs was evaluated.

This is because of a bug in the packages in the ProgrammingExamples
directory.

If you edit the BeginPackage statement to read:

    BeginPackage[ "ProgrammingExamples`ComplexMap`" ]

then this error will not occur. When you load a package using
Needs Mathematica first checks to see if the context in question 
is already on $Packages. If it is then the package will not be 
loaded again. Then Mathematica checks that the context 
specification used to load the package and the context that is 
begun in the BeginPackage statement match. Mathematica then adds that
context to $Packages so ensuring that if you evaluate the 
Needs command again the package will not be loaded a second
time.

For a more detailed discussion of this see section 2.6 of the 
Mathematica book, "Modularity and the Naming of Things". There
is also an article in Volume 6, Issue 2 of The Mathematica
Journal on Contexts and Shadowing by David Wagner which you
might find useful.

I hope this helps.

--Ian

-----------------------------------------------------------
Ian Collier
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217) 398-0700   fax:(217) 398-0747    ianc at wolfram.com
Wolfram Research Home Page:         http://www.wolfram.com/
-----------------------------------------------------------

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Few mathematica commands
  • Next by Date: Re: Fourier? (Q)
  • Previous by thread: Re: packages
  • Next by thread: Re: packages