Re: Needs[] and <<

*To*: mathgroup at smc.vnet.net*Subject*: [mg23106] Re: Needs[] and <<*From*: "Allan Hayes" <hay at haystack.demon.co.uk>*Date*: Wed, 19 Apr 2000 02:30:41 -0400 (EDT)*References*: <8d3qq8$odh@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hans, 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 >Protect[ImplicitPlot]; > >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 BeginPackage["Graphics`ImplicitPlot`","Utilities`FilterOptions`"] >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 >Begin["`Private`"] >Unprotect[ImplicitPlot]; (2) How this package might be dealt with Move Unprotect[ImplicitPlot] up to the position >BeginPackage["Graphics`ImplicitPlot`","Utilities`FilterOptions`"] Unprotect[ImplicitPlot] (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 BeginPackage[.....] 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 End[]; Protect["`*"]; (*protect all existing symbols in the package context*) EndPackage[]; -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Hans Friedrich Steffani" <hans.steffani at e-technik.tu-chemnitz.de> wrote in message news:8d3qq8$odh at smc.vnet.net... > 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 e-technik.tu-chemnitz.de > http://www.tu-chemnitz.de/~hfst/ >