MathGroup Archive 2010

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

Search the Archive

Re: Mathematica daily WTF

In <ies9t9$aa9$1 at> Andrzej Kozlowski <akoz at> writes:

>Actually, there is nothing puzzling about this at all.

>First of all, you are confusing the issue by your assignments =
>Context=Context etc to local variables. This gives exactly the same =

Yes, but also throws half of the puzzle out the window.

Here's another version of the puzzle that is not susceptible to
your too-easy fix.

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

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 can *guess* at the explanation for this, but it is not something
one can readily find in the documentation, certainly not in the
documentation for Block (let alone the one for Attributes).  And
in this explanation, logic counts for absolutely *zilch*.

BTW, the aspect of the puzzle that you pointed out in your reply
is also not made sufficiently clear in the documentation.  I'd bet
that 99.9% of those with programming experience in other languages
would be surprised to discover that in an expression like

  x = Foo[...]

the value "returned" by Foo is not necessarily the value assigned
to x; i.e. after Foo is out of the picture, if Foo happens to be
Block for example, the value it "returned" *can* continue to mutate
before it finally gets assigned to x.  I think that this wide
variance from the semantics that most with programming experience
take for granted alone merits a "daily WTF award".


  • Prev by Date: Re: Mathematica daily WTF (101221T)
  • Next by Date: Re: Mathematica daily WTF (101221T)
  • Previous by thread: Re: Mathematica daily WTF
  • Next by thread: Re: Mathematica daily WTF