MathGroup Archive 2010

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

Search the Archive

Mathematica daily WTF

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114844] Mathematica daily WTF
  • From: kj <no.email at please.post>
  • Date: Mon, 20 Dec 2010 00:39:01 -0500 (EST)

I've often stated that Mathematica is unique in my experience in
that despite my having used it for over two decades, still it
happens that, on average once per session, I am deeply mystified
by something it does.

So, with apologies to Alex Papadimoulis for plagiarizing the title
of his great website (http://thedailywtf.com), I thought I'd post
an example of one of these "daily" (as in, "each day I use
Mathematica") mystifications.

First, by way of background, consider this slightly silly, but
perfectly valid, Mathematica expression:

In[1]:= {Attributes[Context], Attributes[Attributes], 
 Context[Context], Context[Attributes]}

Out[1]= {{HoldFirst, Protected}, {HoldAll, Listable, 
  Protected}, "System`", "System`"}

No surprises here.  Neither should there be any surprises from the
next one, if one groks Block scope:

In[2]:= Block[{Attributes = Attributes, Context = Context},
 {Attributes[Context], Attributes[Attributes], Context[Context], 
  Context[Attributes]}
]

Out[2]= {{HoldFirst, Protected}, {HoldAll, Listable, 
  Protected}, "System`", "System`"}


OK, so much for background. 

What about this one?

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

(The input expression is identical to the previous one, except that
only Context, not Attributes, is localized within the Block scope.

I wont' write what this last one evaluates to, for those who may
want to work it out.  In any case, it's easy enough to paste the
expression into Mathematica to see what it evaluates to.

The following questions are for those who got it right (I usually
don't find after-the-fact rationalizations too illuminating).

If you correctly deduced the output from the last evaluation, would
you *please* explain your reasoning to me?  And how did you arrive
at the knowledge that supports this reasoning?  Is it in the
documentation?

Mystifiedly,

~kj

P.S. Caveat: the outputs shown or alluded to above all come from
v. 7, unfortunately.  It is possible that the results of the
experiments above will be different (and less worthy of a WTF) with
v. 8.  If so, my apologies.


  • Prev by Date: Re: syntax highlighted symbol shadowing for Curl
  • Next by Date: Re: How can I solve semidefinite programming problems? Can any one with
  • Previous by thread: Re: Counting
  • Next by thread: Re: Mathematica daily WTF