Re: unbelievable ...
- To: mathgroup at smc.vnet.net
- Subject: [mg16653] Re: [mg16567] unbelievable ...
- From: Clemens Frey <clemens.frey at bitoek.uni-bayreuth.de>
- Date: Fri, 19 Mar 1999 12:54:03 -0500
- References: <Pine.SOL.4.05.9903180923250.9816-100000@btr0x1.rz.uni-bayreuth.de>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, this indeed i s believable: If you have a=A[1,2] set and define like > > xASet[A[x_,y_],z_]:=(A[x,y]=A[z,y]) > > The first use seems ok: > > {a,xASet[a,3],a} > => {A[1,2],Null,A[3,2]} Then you still have a=A[1,2], but now A[1,2]=A[3,2]. Check this by typing OwnValues[a] and DownValues[A]! So we have a (invisible) replacement chain of a=A[1,2]=A[3,2]. > > But now it is impossible to reset a to A[1,2] (and only to A[1,2] !!!) > > {a=A[1,2],a=A[1,5]} > => {A[3,1],A[1,5]} Now Trace[a=A[1,2]] and see what happens! A[1,2] on the left hand side gets replaced by its downvalue A[3,2], so we have a=A[3,2], and nothing seems to change. But at variance to the upper no we have an immediate replacement rule a=A[3,2]. If you write a=A[1,5] it works like you expect since A[1,5] stays what it is. So to prevent all this stuff, xASet has to be changed, so that the first parameter is changed and not A[..]. The HoldFirst-attribute has to be used in order not to evaluate the first parameter: ClearAll[xASet,a,A]; SetAttributes[xASet,HoldFirst]; xASet[AA_Symbol ,z_] /; MatchQ[AA,A[x_,y_]] := ( AA = A[z,AA[[2]]] ) Now, having a=A[1,2] xASet[a,3] results in no annoying definition for A. DownValues[A] is empty. hope this helped Clemens --------------------------------------------------------- Clemens Frey Post-Graduate Student/Doctoral Candidate Department of Mathematics/BITOEK University of Bayreuth(Germany) clemens.frey at uni-bayreuth.de http://www.bitoek.uni-bayreuth.de/~Clemens.Frey ---------------------------------------------------------