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: [mg61000] Re: [mg60986] Re: Help with output form?
  • From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
  • Date: Fri, 7 Oct 2005 03:37:44 -0400 (EDT)
  • References: <200510060808.EAA08533@smc.vnet.net> <01341327-A0FD-4ACA-9612-13774B37153D@yhc.att.ne.jp>
  • Reply-to: Andrzej Kozlowski <andrzej at akikoz.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 6 Oct 2005, at 21:07, Andrzej Kozlowski wrote:

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


Perhaps I should add that this is more serious than it may seem,  
since the fucntion x could actually be defined in some package so  
that the user doesn't know that x was defined via dynamic  
programming. This makes me feel that this approach is in fact unsafe.

Andrzej Kozlowski


  • Prev by Date: Re: Assigning (really dumb question)
  • Next by Date: Re: MathML, Mozilla, fonts and Mathematica 5.2
  • Previous by thread: Re: Re: Help with output form?
  • Next by thread: Opinions?:Foundations of Fluid Mechanics with Applications