Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

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

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg99224] Re: HoldForm in defined function doesn't seem to work
  • From: David Bailey <dave at>
  • Date: Thu, 30 Apr 2009 06:23:00 -0400 (EDT)
  • References: <gt9aki$q22$>

joel.aufgang at 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.
You need to define f to have the HoldAll attribute - otherwise its 
argument is evaluated long before it becomes the argument to HoldForm!


If you are interested in working with held expressions, it is worth 
reading around the subject, and experimenting a bit. Also read up on 
Evaluate and Unevaluated.

If you want BoxTree to display the unevaluated expression, it too should 
be given the HoldAll (or possibly HoldFirst) attribute.

David Bailey

  • Prev by Date: Re: How to select several cells
  • Next by Date: Re: Simplify exponents in output
  • Previous by thread: Re: HoldForm in defined function doesn't seem to work
  • Next by thread: Export Mathematica->Excel [specific sheet]