MathGroup Archive 2000

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

Search the Archive

Re: Needs[] and <<

  • To: mathgroup at
  • Subject: [mg23106] Re: Needs[] and <<
  • From: "Allan Hayes" <hay at>
  • Date: Wed, 19 Apr 2000 02:30:41 -0400 (EDT)
  • References: <8d3qq8$>
  • Sender: owner-wri-mathgroup at

I recall getting error messages on early versions of Mathematica by loading a
package twice using <<.
Using Needs avoided this, by not allowing repeat loadings, but may be that
the reason for Needs was to economise on loading time.

I discuss below
(1) A current Add-on that exhibits this behaviour
(2) How this package might be dealt with
(3) A simple general way to avoid the problem

(1) I have just looked at the Algebra and Graphics Add-ons and found this
behaviour only with  Graphics`ImplicitPlot` [it does not interfere with the
functiong of the package]

The the reason for the behaviour is as follows.
At the end of the package we find the standard protection of exported
symbols (here only Implicit Plot is exported): thus

>End[] (* "`Private`" *)
>EndPackage[]  (* "Graphics`ImplicitPlot`" *)

*Now*, if we load the  package twice using <<, then the second time round we
find near the start of the package


>ImplicitPlot::usage = ..........
>Options[ImplicitPlot] = ..........

At this stage ImplicitPlot is protected from the first loading, so:
--changes in the usage message would be effective, since message definitions
can be made for protected symbols,
- but the definition Options[ImplicitPlot] = ..... will not be effective,
and a message will be generated.

Then we come to


(2) How this package might be dealt with

Move Unprotect[ImplicitPlot] up to the position



(3) A simple general way to avoid the problem without having to type in all
the names of the exported functions

Begin the programming section ot a package with


Unprotect["`*"] (*unprotect all existing symbols in the package context*)

We might also add

ClearAll["`*"] ((*clear all existing attributes and definitions for these
symbols* )

End the programming section with


Protect["`*"]; (*protect all existing symbols in the package context*)


Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Hans Friedrich Steffani" <hans.steffani at> wrote in
message news:8d3qq8$odh at
> Why does the examples in the Mathematica book say
> << Graphics`Graphics`
> instead of
> Needs["Graphics`Graphics`"]
> ?
> Hans Friedrich Steffani
> --
> Hans Friedrich Steffani
> Institut fuer Elektrische Maschinen und Antriebe, TU Chemnitz
> mailto:hans.steffani at

  • Prev by Date: Re: Keyboard shortcuts do not work
  • Next by Date: Re: Help! Mathematica on my 500MHz outperforms my GHz machine!
  • Previous by thread: Re: Needs[] and <<
  • Next by thread: Add Fonts when using Display[]