Re: SetAttributes for entire package

*To*: mathgroup at smc.vnet.net*Subject*: [mg111392] Re: SetAttributes for entire package*From*: David Reiss <dbreiss at gmail.com>*Date*: Fri, 30 Jul 2010 06:56:47 -0400 (EDT)*References*: <i2rm0v$r4s$1@smc.vnet.net>

The workaround is in my original post (or do I misunderstand?). I am puzzled though with the example you show. You are acting with SetAttributes on Strings. SetAttrubutes doesn't accept a string as its firs argument. When I try your example in my Mathematica it doesn't work... Here is my session: In[1]:= BeginPackage["test`"]; f[x_] := 2 x g[x_] := 1/x EndPackage[]; In[7]:= SetAttributes[#, {Locked, ReadProtected}] & /@ Names["test`*"] Out[7]= {SetAttributes["f", {Locked, ReadProtected}], SetAttributes["g", {Locked, ReadProtected}], SetAttributes["x", {Locked, ReadProtected}]} SetAttributes::sym: Argument f at position 1 is expected to be a symbol. >> SetAttributes::sym: Argument g at position 1 is expected to be a symbol. >> SetAttributes::sym: Argument x at position 1 is expected to be a symbol. >> General::stop: Further output of SetAttributes::sym will be suppressed during this calculation. >> In[8]:= Attributes[g] Out[8]= {} On Jul 29, 6:43 am, Bill Rowe <readn... at sbcglobal.net> wrote: > On 7/28/10 at 2:54 AM, dbre... at gmail.com (David Reiss) wrote: > > >This would be quite simple if SetAttrubutes accepted string > >arguments. If it did then you could simply execute > >SetAttributes[#,{Locked, ReadProtected}]&[Names["mycontext`*]] > >where mycontext is your package context. Howe er SetAttributes does > >not work this way (but it should...). > >So one has to work around this. I had to do this years ago when > >creating a password protection scheme for > >http://scientificarts.com/worklife > > You didn't say what your work around was. I note the following > > In[1]:= BeginPackage["test`"]; > f[x_] := 2 x > g[x_] := 1/x > EndPackage[]; > > In[5]:= SetAttributes[#, {Locked, ReadProtected}] & /@ Names["test`*"]; > > In[6]:= Attributes[g] > > Out[6]= {Locked,ReadProtected} > > In[7]:= Attributes[f] > > Out[7]= {Locked,ReadProtected} > > Given this does what you seem to want and requires about the > same number of keystrokes to enter, if you consider this a "work > around" I contend it doesn't involve any significant effort. And > given this does the job, it isn't clear to me any thing needs to > be changed.