Re: Loading Packages in a loop
- To: mathgroup at smc.vnet.net
- Subject: [mg84480] Re: Loading Packages in a loop
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 27 Dec 2007 03:43:14 -0500 (EST)
- References: <fknvm0$6cq$1@smc.vnet.net> <fkt9l0$6i9$1@smc.vnet.net>
Hi, suppose you have a package (that you don't show us even in a simplified example) -------------------------------------------------------- BeginPackage["test`"] test::usage="test[] does something very important." Begin["`Private`"] test[]:=Print["Ho, ho ho ..."] End[] EndPackage[] SetAttributes[test`test,{Locked,Protected}] -------------------------------------------------------- Needs["Utilities`CleanSlate`"] Get["test.m"]; Do[$HistoryLength = 0;(*some other things to save memory and to waste time *) Unprotect[In, Out];(*some other things to save memory because you never found out what ClearInOut[] does *) Clear[In, Out];(*some other things to save memory*) Protect[In, Out];(*some other things to save memory*) test`test[];(*call my function*) CleanSlateExcept["Global`"], {i, 4}]; will survive .. Regards Jens BTW CleanSlateExcept["Global`","test`"]]; Matthias Gottschalk wrote: > Hello Jens > > Sorry, these are no solutions. > > The first proposed change > > >> << CleanSlate.m; >> >> >> Do[ >> $HistoryLength = 0; (* some other things to save >> memory >> *) >> Unprotect[In, Out]; (* some other things to save >> memory >> *) >> Clear[In, Out]; (* some other things to save >> memory >> *) >> Protect[In, Out]; (* some other things to save >> memory >> *) >> Get["myPackage`"];(* reload my package *) >> PackageFunktion[]; (* call my function *) >> CleanSlateExcept["Global`"], (* clean my context *) >> {i,n} >> ]; > > produces the same > > PackageFunktion::shdw: "Symbol PackageFunktion appears in > multiple contexts {myPackage`,Global`} definitions in > context myPackage` may shadow or be shadowed by other > definitions." > > error. > > The second change > >> << CleanSlate.m; >> Needs["myPackage`"]; >> >> Do[ >> $HistoryLength = 0; (* some other things to save >> memory >> *) >> Unprotect[In, Out]; (* some other things to save >> memory >> *) >> Clear[In, Out]; (* some other things to save >> memory >> *) >> Protect[In, Out]; (* some other things to save >> memory >> *) >> DeclarePackage["myPackage`","PackageFunktion"]; >> PackageFunktion[]; (* call my function *) >> CleanSlateExcept["Global`"], (* clean my context *) >> (* reload my package *) >> {i,n} >> ]; >> > > is like my first version. It runs once the loop > successfully and does not know the package functions in > the after the call to ClearSlate. > > Matthias > >