Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: How to use HoldForm within Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15276] Re: How to use HoldForm within Module
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 31 Dec 1998 04:39:31 -0500
  • References: <76cijv$o48@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Chee Lim Cheung wrote in message <76cijv$o48 at smc.vnet.net>...
>Hello Mathematica gurus,
>
>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?
>
>Thanks
>Chee
>

Chee,
In your code, the function f is evaluated before being passed to the
right side.
This can be prevented by giving doNOTCHANGE the attribute HoldAll:

Attributes[doNOTCHANGE] = HoldAll;

In[1]:=
doNOTCHANGE[f_] := Module[{g}, g = HoldForm[f]; Print[g]]

In[2]:=
doNOTCHANGE[1(UnitStep[t - 1] - UnitStep[t - 2])]

    1 (UnitStep[t - 1] - UnitStep[t - 2])

If you don't need the Module then

Attributes[doNOTCHANGE2] = HoldAll;

In[3]:=
doNOTCHANGE2[f_] := Print[HoldForm[f]]

In[4]:=
doNOTCHANGE2[1(UnitStep[t - 1] - UnitStep[t - 2])]

1 (UnitStep[t - 1] - UnitStep[t - 2])


Allan


---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565




  • Prev by Date: Cell Bracket Notation
  • Next by Date: A question on viewing 3D Graphics
  • Previous by thread: RE: How to use HoldForm within Module
  • Next by thread: mathlink program hanging in MLAnswer