RE: How to use HoldForm within Module
- To: mathgroup at smc.vnet.net
- Subject: [mg15274] RE: [mg15259] How to use HoldForm within Module
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 31 Dec 1998 04:39:30 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Chee wrote: _________________ I am new to Mathematica. I need to use a function in its original form within Module. e.g.,doNOTCHANGE[f_]:=Module[{g},g=HoldForm[f];Print[g]] may not give what I want as f is already rearranged according to Mathematica's lexicographical order within Module,i.e.,HoldForm[f] in Module may not be exactly of the same form as f as defined. One example is f=-1(UnitStep[t-1]-UnitStep[t-2]).Can any of you out there show me the way to get f in its original form inside Module? _________________ Chee, You will close to what you want if you give doNOTCHANGE the HoldAll attribute (see below). This way your function will not evaluate the argument before evaluating Module and all the stuff inside. However, you probably don't get what you want for Out[4] below, and I can't see how you could ensure Mathematica does. In[1]:= SetAttributes[doNOTCHANGE,HoldAll] In[2]:= doNOTCHANGE[f_]:=Module[{g},g=HoldForm[f];Print[g]] In[3]:= doNOTCHANGE[-1(UnitStep[t-1]-UnitStep[t-2])] -(UnitStep[t-1]-UnitStep[t-2]) In[4]:= expr=-(UnitStep[t-1]-UnitStep[t-2]); doNOTCHANGE[expr] expr Cheers, Ted Ersek