MathGroup Archive 2009

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

Search the Archive

Re: HoldForm in defined function doesn't seem to work


The function needs to have the attribute HoldAll or HoldFirst

f[x_] = HoldForm[x];

SetAttributes[g, HoldAll]

g[x_] = HoldForm[x];

f[113 456 789]

40655592

g[113 456 789]

113 456 789

Attributes[HoldForm]

{HoldAll,Protected}


Bob Hanlon

---- 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.




  • Prev by Date: Re: why is this happening?
  • Next by Date: Convex hull
  • Previous by thread: Re: why is this happening?
  • Next by thread: Re: HoldForm in defined function doesn't seem to work