MathGroup Archive 2005

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

Search the Archive

Re: Re: Help with output form?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60998] Re: [mg60986] Re: Help with output form?
  • From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
  • Date: Fri, 7 Oct 2005 03:37:43 -0400 (EDT)
  • References: <200510060808.EAA08533@smc.vnet.net>
  • Reply-to: Andrzej Kozlowski <andrzej at akikoz.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 6 Oct 2005, at 17:08, ted.ersek at tqci.net wrote:

> A user wanted to make it so that evaluating
> (lhs=rhs) would make the assignment and show
> lhs=rhs in the output instead of just rhs.
> The following more or less does this.
>
>
> In[1]:=
>   Unprotect[Set];
>   $ModifySet=True;
>
>   (lhs_=rhs_)/;$ModifySet:=
>      Block[{$ModifySet}, lhs=rhs; HoldForm[lhs=rhs] ]
>
>   Protect[Set];
>
>
> In[5]:=
>   y=Expand[(a+b)^2]
>
> Out[5]=
>   y = a^2 + 2 a b + b^2
>
>
> But then you will have trouble if you use the above output cell to  
> make a
> new input expression.  That can be fixed if you use a package I have
> posted at
>   http://library.wolfram.com/infocenter/MathSource/705/
>
> Then change HoldForm above to HoldTemporary.
>
> ----------
>    Regards,
>      Ted Ersek
>
>
>
>


This is admittedly clever and elegant but making any changes to basic  
functions like Set can have unforeseen side effects. Of course here  
we are protected by the flag $ModifySet, which has to be set to True  
before modification will work but one might set it to True and forget  
about it.  We may then run into trouble when we try to use "dynamic  
programming", as in for example:

x[0] = 0; x[1] = 1; x[n_] := x[n] = x[n - 1] + x[n - 2];

Now try evaluating x[100] with $ModifySet set to False and set to True.

Andrzej Kozlowski


  • Prev by Date: Re: Assigning (really dumb question)
  • Next by Date: Re: Assigning (really dumb question)
  • Previous by thread: Re: Help with output form?
  • Next by thread: Re: Re: Help with output form?