MathGroup Archive 2010

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

Search the Archive

Re: Mathematica daily WTF

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114873] Re: Mathematica daily WTF
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 21 Dec 2010 00:18:33 -0500 (EST)
  • References: <201012200539.AAA22695@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

I'd love to know just what you were doing in your work that session that 
led you to even think of asking for such things as Attributes[Context], 
etc. (Or were you just looking for "trouble"?)

On 12/20/2010 12:39 AM, kj wrote:
> 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.
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: [Question] NonlinearRegress with two independent variables
  • Next by Date: Re: Shift-Ctrl-N and Manipulate
  • Previous by thread: Mathematica daily WTF
  • Next by thread: Re: Mathematica daily WTF