Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Making command called HoldTemporary

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7693] Making command called HoldTemporary
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Sun, 29 Jun 1997 22:17:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I made further progress on the HoldTemporary command I am trying
to build.  See below.

The idea behind HoldTemporary is to prevent further simplification
or ordering of terms in the expression, but allow the user to
perform later work on the result as if it was completely evaluated
(not held). The code I show below does this for a limited number
of cases.  More work is needed to make it complete.  But as Fermat
said this margin is too small to include the details.

It's better to use  MakeBoxes instead  of Format.  Why? Because you
can edit the output made by MakeBoxes, and it will be treated as a
new expression.  The Mma Book says MakeBoxes should be used
recursivly.  It seems the kernal automatically makes the  first call
to MakeBoxes to determine how the result should be displayed.
MakeBoxes must have two arguments.  For the second argument
"form_" the kernal will use the specified Form  for the Cell evaluated
(ie.  TraditionalForm, StandardForm, etc. ).

In the code below I make FullForm lie about what the
FullForm of the temporary held result is.  Then I need
to make special rules for commands like Part to give the
appearance that the displayed  FullForm is correct.

     Ted Ersek
     ersek_ted%pax1a at mr.nawcad.navy.mil
 ----------------- ------------------------ -------------------

In[1]:=
    $WillReleaseHoldTemporary= {Plus, Times, Power, Exp, Integrate,
                                                            (*  and many 
others  *) };

    SetAttributes[HoldTemporary, HoldAll]

    HoldTemporary/:MakeBoxes[HoldTemporary[expr_], form_]:=
    MakeBoxes[expr, form]

    HoldTemporary/:g_[a___,HoldTemporary[expr_], b___]/;
    MemberQ[$WillReleaseHoldTemporary, g]:=g[a, expr, b]

    Unprotect[FullForm];
    FullForm/:MakeBoxes[FullForm[HoldTemporary[expr_]], form_]:=
    MakeBoxes[FullForm[expr], form];
    Protect[FullForm];

    HoldTemporary/:Part[HoldTemporary[expr_], n_]/;(Head[n]=!=List):=
    Part[Hold[expr], 1, n]



In[7]:=
    foo=HoldTemporary[z+2+d+a+3]
Out[7]=
    z+2+d+a+3


In[8]:=
    foo-d+4
Out[8]=
    9+a+z



In[9]:=
    HoldTemporary[z+2+d+a+3]//FullForm
Out[9]=
    Plus[z, 2, d, a, 3]



In[10]:=
    Integrate[foo,z]
Out[10]=
    (5+a+d) z+z^2/2



In[11]:=
    Part[foo,4]
Out[11]=
    a



  • Prev by Date: Re: using indexed variables in MultiplierMethod[ ], etc.
  • Next by Date: D[f,x] vs f'[x]
  • Previous by thread: Re: using indexed variables in MultiplierMethod[ ], etc.
  • Next by thread: D[f,x] vs f'[x]