MathGroup Archive 2010

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

Search the Archive

Re: Mathematica daily WTF

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114952] Re: Mathematica daily WTF
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 24 Dec 2010 04:10:48 -0500 (EST)

On 12/23/10 at 3:54 AM, no.email at please.post (kj) wrote:

>The mimic of Attributes defined below works the same inside the
>Block as it does outside it, as long as the localized value is the
>same as the global value (this last condition makes the statement
>sound almost tautological, but the point is that the same
>near-tautology does not hold for Attributes, nor for many other
>symbols in System`):

>In[1]:= attributes = Function[s, Attributes[s],
>Evaluate[Attributes[Attributes]~Complement~{Protected}]];

>In[2]:= Block[{attributes = attributes, Context = Context},
>Print[attributes[{Context, Sin}]];
>]

>{{}, {Listable, NumericFunction, Protected}}

>In[3]:= Block[{Context = Context}, Print[attributes[{Context, Sin}]];
>]

>{{}, {Listable, NumericFunction, Protected}}

>IOW, Block-localization doesn't turn attributes into an inert
>symbol, the way it does to Attributes.  Replacing attributes by
>Attributes throughout In[2] and In[3] will show that
>Block-localization as shown radically alters Attributes behavior.

I am not convinced there is anything strange about the way
Attributes and Block work together. It seems to me the reason

Block[{Context = Context}, Attributes[Context]]

yields {} is that the attributes of the local variable simply
are not inherited when using Set. That is:

In[1]:= Attributes[f] = {Listable};
g = f;
Attributes[{f, g}]

Out[3]= {{Listable},{}}

Adding more layers of abstraction won't change this behavior.
Additional layers of abstraction simply obscures the fact that
Set doesn't pass on attributes.



  • Prev by Date: Re: Map function with 2 variables
  • Next by Date: Re: Map function with 2 variables
  • Previous by thread: Re: Mathematica daily WTF
  • Next by thread: Re: Mathematica daily WTF