Re: HoldForm in defined function doesn't seem to work
- To: mathgroup at smc.vnet.net
- Subject: [mg99220] Re: HoldForm in defined function doesn't seem to work
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Thu, 30 Apr 2009 06:22:17 -0400 (EDT)
- References: <gt9aki$q22$1@smc.vnet.net>
It's because of the attributes of HoldForm and f:
In[561]:= Attributes[HoldForm]
Out[561]= {HoldAll, Protected}
In[562]:= Attributes[f]
Out[562]= {}
HoldForm doesn't evaluate its arguments, but f having no attributes at
all does. So, it receives it argument evaluated.
Cheers -- Sjoerd
On Apr 29, 12:37 pm, joel.aufg... 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.