Re: Question on Unevaluated
- To: mathgroup at smc.vnet.net
- Subject: [mg117287] Re: Question on Unevaluated
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Mon, 14 Mar 2011 05:58:30 -0500 (EST)
----- Original Message ----- > From: "Alexey" <lehin.p at gmail.com> > To: mathgroup at smc.vnet.net > Sent: Sunday, March 13, 2011 5:26:42 AM > Subject: [mg117264] Question on Unevaluated > Hello, > > I am puzzled a bit by the Documentation for Unevaluated. Under "More > information" field we read: > > "f[Unevaluated[expr]] effectively works by temporarily setting > attributes so that f holds its argument unevaluated, then evaluating > f[expr].". > > After reading this I expect that > > f[Unevaluated[1 + 1]; 2 + 1] > > will be returned completely unevaluated as it is when I set HoldFirst > attribute to f: > > In[2]:= SetAttributes[f, HoldFirst] > f[Unevaluated[1 + 1]; 2 + 1] > > Out[3]= f[Unevaluated[1 + 1]; 2 + 1] > > But in really we get > > In[1]:= f[Unevaluated[1 + 1]; 2 + 1] > > Out[1]= f[3] > > This leads me to a question: what is implied in documentation? Which > attributes are temporarily set and to which function? In your example the "funtion" in question would be CompoundExpression. So Mathematica is indeed acting as documented here. By way of contrast, note the effect for the examples below. In[18]:= f[Unevaluated[1 + 1], 2 + 1] Out[18]= f[Unevaluated[1 + 1], 3] In[19]:= f[Unevaluated[1 + 1; 2 + 1]] Out[19]= f[Unevaluated[1 + 1; 2 + 1]] You can have Mathematica show the structure simply by wrapping with FullForm[Hold[...]] In[22]:= Hold[f[Unevaluated[1 + 1]; 2 + 1]] // FullForm Out[22]//FullForm= FullForm[Hold[f[Unevaluated[1 + 1]; 2 + 1]]] Daniel Lichtblau Wolfram Research