Re: shadow-proofing a package
- To: mathgroup at smc.vnet.net
- Subject: [mg42724] Re: [mg42712] shadow-proofing a package
- From: Dr Bob <drbob at bigfoot.com>
- Date: Wed, 23 Jul 2003 00:25:15 -0400 (EDT)
- References: <200307220840.EAA19569@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
That's essentially the method used in Notation.m Or here's my own utility package, featuring the same method: BeginPackage["DrBob`Utility`"] Unprotect[Evaluate[$Context<>"*"]]; ClearAll[Evaluate[$Context<>"*"]]; DrBob`Utility::gshadw="The symbol '`1`' has been used in the global context. \ The DrBob`Utility` package needs the full use of the symbol '`1`' and has \ therefore removed this symbol from the global context."; Begin["`Private`"] publicFunctions= Map[StringJoin["Global`",#1]&,{"animate","browse","divvy","divvySort", "self","subFunction","test","testOption","testMax ","testFst","zeroQ"}]; overideNames=Intersection[Names["Global`*"],publicFunctions]; If[overideNames=!={},((Message[DrBob`Utility::gshadw,#1]&)/@(StringDrop[#1, 7]&)/@overideNames; Unprotect/@overideNames; ClearAll/@overideNames; Remove/@overideNames; Null)]; End[] ... usage statements here ... Begin["`Private`"] ... function definitions ... End[] Protect[Evaluate[$Context<>"*"]]; EndPackage[]; Bobby On Tue, 22 Jul 2003 04:40:46 -0400 (EDT), Selwyn Hollis <selwynh at earthlink.net> wrote: > The following occurred to me as a way to prevent the shadowing problem: > > Before BeginPackage["blah`blahblah`"] put > > Remove@@( StringJoin["Global`",#]&/@ > Intersection[Names["Global`*"], > {"name1", "name2", ... for all symbols defined in the package}] ) > > This seems to work well. But surely there must be some downside to it, or > else it would already be the recommended way of doing things. What am I > overlooking here? > > ----- > Selwyn Hollis > http://www.math.armstrong.edu/faculty/hollis > > -- majort at cox-internet.com Bobby R. Treat
- References:
- shadow-proofing a package
- From: Selwyn Hollis <selwynh@earthlink.net>
- shadow-proofing a package