MathGroup Archive 2003

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

Search the Archive

Re: Re: shadow-proofing a package

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42741] Re: [mg42724] Re: [mg42712] shadow-proofing a package
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 24 Jul 2003 04:10:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

As others have pointed out, a properly written program does not erase  
or remove definitions made by the user without first saving them  
somewhere else or at least giving the user a chance to do so. However,  
you can modify your package so that it first "moves" all such symbols,  
together with their DownValues, UpValues etc, to a newly created  
context (which should be different from any existing one).

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/



On Wednesday, July 23, 2003, at 06:25 AM, Dr Bob wrote:

> 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
>
>
>


  • Prev by Date: RE: Input Line Evaluation
  • Next by Date: Re: Re: shadow-proofing a package
  • Previous by thread: DOUBLE COLUMN TEXT CELL
  • Next by thread: Re: Re: shadow-proofing a package