Re: HoldForm in defined function doesn't seem to work
- To: mathgroup at smc.vnet.net
- Subject: [mg99215] Re: [mg99182] HoldForm in defined function doesn't seem to work
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Thu, 30 Apr 2009 06:21:23 -0400 (EDT)
- References: <200904291037.GAA26696@smc.vnet.net>
When you define your f, you are missing the HoldAll attribute. The argument then gets evaluated before being passed to f. Here is what is needed: In[1] = SetAttributes[f,HoldAll]; f[x_]:=HoldForm[x]; In[2] = HoldForm[123 456 789] Out[2] =123 x 456 x 789 You could also use Ownvalues, in which case this problem is avoided (g serves as a "function pointer" to HoldForm): In[3] = g = HoldForm; In[4] = g[123 456 789] Out[4] = 123 x 456 x 789 Regards, Leonid On Wed, Apr 29, 2009 at 3:37 AM, <joel.aufgang at gmail.com> wrote: > I'm struggling to understand why this doesn't work: > > > f[x_] = HoldForm[x]; > HoldForm[123 456 789] (* returns "123 x 456 x 789" *) > f[123 456 789] (* returns"44253432" *) > > I don't understand why the two results are different. Is there a > special trick I need to do to be able to define f so that the HoldForm > works? > > I'm using this to help visualize the way a notebook represents typed > expressions, so I'm trying to do something like this: > > BoxTree[expr_] := TreeForm[ToBoxes[HoldForm[expr]][[1]]]; > a b c d e // BoxTree > 123 456 789 // BoxTree (* want this to show as a RowBox like the > previous example *) > > > Any help would be greatly appreciated. Thanks. > >
- References:
- HoldForm in defined function doesn't seem to work
- From: joel.aufgang@gmail.com
- HoldForm in defined function doesn't seem to work