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 smc.vnet.net
  • Subject: [mg99266] Re: HoldForm in defined function doesn't seem to work
  • From: joel.aufgang at gmail.com
  • Date: Fri, 1 May 2009 05:23:44 -0400 (EDT)
  • References: <gt9aki$q22$1@smc.vnet.net> <gtbuo8$2r4$1@smc.vnet.net>

Wow!  What a great number of responses. Thanks to all of you who
helped me out with this.

The SetAttributes[f,HoldAll]  solution was just what I was looking
for.



Unfortunately, I'm still stuck on something....  Namely, using this
with the Map function.

I'm trying to display the way the notebook front end rewrites the box
model representation of an expression as it is edited.  I'd like to
display a sequence of expressions and their ToBoxes representations
using a SlideView.   So I'm doing something like this:

==========================
==============

ShowBoxForms[expr_] := TableForm[ {HoldForm[expr], ToBoxes[HoldForm
[expr]][[1]], TreeForm[ToBoxes[HoldForm[expr]][[1]]]}];
EditingSequence[expr_] := SlideView[Map[ShowBoxForms, expr],
AppearanceElements -> All];
SetAttributes[ShowBoxForms, HoldAll];
SetAttributes[EditingSequence, HoldAll];
{a, a b, a b c, a b c/d} // EditingSequence
{a, ab, a b, a b c, a b c^2, a b + c^2, a (b + c)^2, a (b + c)^
(2/3)} // EditingSequence
{12, 12 34, 12 34/56} // EditingSequence

==========================
==============

Unfortunately, even though I am setting the HoldAll attributes on my
functions, the hold is being removed when the Map function is being
called. You can see this by looking at the third editing sequence in
my example, where the numeric expressions are being evaluated before
being converted to boxes.  "12 34/56 // ShowBoxForms"  Works
perfectly, but I need it to display the same way when being called
through EditingSequence

I've tried setting HoldAll on Map, but that messes everything up even
more.  Doing this holds the entire list from the argument, which
causes Map to be applied to the entire list and not each element.  I
need to be able to use Map while performing a HoldForm on each element
of the input argument list.

Any help with this would be greatly appreciated.  And Thanks again for
the previous help as well.

Joel.


On Apr 30, 6:32 am, mju... at gmail.com wrote:
> On Apr 29, 9: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.
>
> That's the way Mathematica evaluates expressions. To achieve the
> desired effect add command:
> SetAttributes[f,HoldAll]
>
> Best wishes, Yuri



  • Prev by Date: Re: Re: NDSolve initial value problem
  • Next by Date: FindFit and complex data
  • Previous by thread: Re: HoldForm in defined function doesn't seem to work
  • Next by thread: Re: HoldForm in defined function doesn't seem to work