Re: Unevaluated Expression
- To: mathgroup at smc.vnet.net
- Subject: [mg26999] Re: [mg26962] Unevaluated Expression
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 30 Jan 2001 23:22:19 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I am afraid that you do not make it clear enough (at least for me) what really you would like f to return. For example, why is the following simple method not satisfactory? In[1]:= f[x_] := x^2 In[2]:= a = 10: In[3]:= f[HoldForm[a]] Out[3]= 2 a In[4]:= ReleaseHold[%] Out[4]= 100 Alternatively perhaps you prefer the arguments of f not evaluate at all (without needing HoldForm in the input): In[5]:= Clear[f] In[6]:= SetAttributes[f, HoldAll] In[7]:= f[x_] := HoldForm[x]^2 In[8]:= f[a] Out[8]= 2 a In[9]:= ReleaseHold[%] Out[9]= 100 And by the way, I can't understand the point of the codes you give at the end of your posting. In particular, Composition[Hold] evaluates simply to Hold, and f plays no role at all in the code, it might equally well be replaced by any atomic expression you like, for example 0: In[17]:= First[Level[Composition[Hold][f[#]], {-1}]] & /@ {a, 10} Out[17]= {10, 10} In[18]:= First[Level[Composition[Hold][0[#]], {-1}]] & /@ {a, 10} Out[18]= {10, 10} In[19]:= First[Level[Hold[0[#]], {-1}]] & /@ {a, 10} Out[19]= {10, 10} -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ http://sigma.tuins.ac.jp/ on 01.1.30 5:38 PM, Hermann Meier at hmeier at webshuttle.ch wrote: > Dear Mathematica users, > > a = 10; > Unprotect[ToString]; SetAttributes[ToString, HoldAll] > ToString[a]//FullForm > gives (as desired) "a", not 10 > > > Then I wanted to prevent the argument in f[x_] := x^2 from > getting evaluated. > > Attributes[f] = {HoldAll} > f[x_] := x^2 > f[Unevaluated[a]] > gives 100. > > The longwinded code > ToExpression[ToString[f[a]], InputForm, Hold] /. Hold[f[nr_]] -> nr > or > First[Level[Composition[Hold][f[#]],{-1}]]& /@ {a,10} > > at least manages to give 10 instead of 100. > > Is there really no way to prevent the argument in f[x] from firing ? > (I use Mathematica 4.1 for Windows). > > > With best regards > Hermann Meier > > > > > > > > > >