Re: "unload" a package

*To*: mathgroup at smc.vnet.net*Subject*: [mg70842] Re: "unload" a package*From*: "David Reiss" <dbreiss at gmail.com>*Date*: Sat, 28 Oct 2006 23:39:00 -0400 (EDT)*References*: <ehv91l$g7s$1@smc.vnet.net>

Yes, this can be done. However, you need to also so some more things 1) Unprotect all of the parameters in the context 2) remove all of the parameters it the context 3) remove all of the parameters it the Private` subcontext of the context 4) remove the context from the parameter $Packages (Unprotect $Packages first, then Protect it) 5) remove the context pathe from $ContextPath If there are any functions within the context that are Locked then all best are off If the package depends on other packages then this process may need to be done to those as well If other packages depend on the package you are removing then they will cease to work. This is the general procedure that I use in the RemovePackage function in my WorkLife FrameWork package: http://scientificarts.com/worklife Best regards, David dimitris wrote: > Hello to all. > > I wondered how someone can "UNLOAD" a package > without "kill" the Kernel? > > That is, is there a command that does the opposite of Get or Needs? > > After the Chriss Chiasson and David Park's responses (thanks a lot both > of you!!!) and their suggestion for using Remove I tried to experiment > myself, practise which resulted in a bigger query. > > Before proceeding to my question Copy/Paste the > following in a notebook, select the Cells and execute the commands. > > ---------------------------------------------------------------------------------------------------------- > > Print[StyleForm["Version I work", FontColor -> Blue, FontWeight -> > "Bold"]] > $Version > > Print[StyleForm["Load the package", FontColor -> Blue, FontWeight -> > "Bold"]] > Needs["Graphics`Graphics`"] > > Print[StyleForm["Built-in Symbols inside the package", FontColor -> > Blue, > FontWeight -> "Bold"]] > Names["Graphics`Graphics`*"] > > Print[StyleForm["An example", FontColor -> Blue, FontWeight -> "Bold"]] > DisplayTogether[Plot[x, {x, 1, 2}], Plot[2*x, {x, 1, 2}]]; > > Print[StyleForm["Remove all the Built-in Symbols\nof the package from > the Kernel", FontColor -> Blue, FontWeight -> "Bold"]] > Remove["Graphics`Graphics`*"] > > Print[StyleForm["Check", FontColor -> Blue, FontWeight -> "Bold"]] > Information["Graphics`Graphics`*", LongForm -> False] > > Print[StyleForm["Reload the package", FontColor -> Blue, > FontWeight -> "Bold"]] > Needs["Graphics`Graphics`"] > > Print[StyleForm["Built-in Symbols inside the package", FontColor -> > Blue, > FontWeight -> "Bold"]] > Names["Graphics`Graphics`*"] > Print[StyleForm["!!!", FontColor -> Blue, FontWeight -> "Bold"]] > > Print[StyleForm["Kill the Kernel", FontColor -> Blue, FontWeight -> > "Bold"]] > Quit > > Print[StyleForm["Re-re-load the package (...)", FontColor -> Blue, > FontWeight -> "Bold"]] > Needs["Graphics`Graphics`"] > > Print[StyleForm["Built-in Symbols inside the package", FontColor -> > Blue, > FontWeight -> "Bold"]] > Names["Graphics`Graphics`*"] > > Print[StyleForm["Kill the Kernel", FontColor -> Blue, FontWeight -> > "Bold"]] > Quit > > Print[StyleForm["Re-re-re-load the package (...)", FontColor -> Blue, > FontWeight -> "Bold"]] > Needs["Graphics`Graphics`"] > > Print[StyleForm["Built-in Symbols inside the package", FontColor -> > Blue, > FontWeight -> "Bold"]] > Names["Graphics`Graphics`*"] > > Print[StyleForm["Clear all the Built-in Symbols\nof the package from > the Kernel", > FontColor -> Blue, FontWeight -> "Bold"]] > Clear["Graphics`Graphics`*"] > > Print[StyleForm["Check I", FontColor -> Blue, FontWeight -> "Bold"]] > Information["Graphics`Graphics`*", LongForm -> False] > > Print[StyleForm["Check II", FontColor -> Blue, FontWeight -> "Bold"]] > DisplayTogether[Plot[x, {x, 1, 2}], Plot[2*x, {x, 1, 2}]] > > Print[StyleForm["Check III", FontColor -> Blue, FontWeight -> "Bold"]] > Needs["Graphics`Graphics`"] > Print[StyleForm["Again problem", FontColor -> Blue, FontWeight -> > "Bold"]] > DisplayTogether[Plot[x, {x, 1, 2}], Plot[2*x, {x, 1, 2}]] > > --------------------------------------------------------------------------------------------------------------- > > And here comes my question! > > Ok, with Remove["Graphics`Graphics`*"] you avoid to refresh the Kernel > in order to "unload" (...somehow..) the package. > > However, in order to reload again the package you MUST refresh the > Kernel! > BUT, this is what I want to avoid! > > The same holds true, more or less, for Clear. > > Anyway for those that are interested in the subject, > there is forum for Mathematica (I think Chris Chiasson is responsible > for it; see http://groups.google.com/group/mathematica) > and look what someone answered me: > > "I think that there is no reliable way to do this. > However, take a look at the CleanSlate package in > ExtraPackages/Utilities. The documentation is inside the CleanSlate.m > file. But keep in mind that this package is not very reliable. > You can also read about contexts. The functions imported from packages > usually reside in their own context." > > What do you believe? > > I really appreciate any guidance/further insight. > Thanks in advance for any response > > Dimitris Anagnostou