Self destructing definitions
- To: mathgroup at yoda.physics.unc.edu
- Subject: Self destructing definitions
- From: LELMA at basin.crc.uno.edu
- Date: Mon, 9 Mar 1992 14:14 CST
A colleague of mine is having the following problem with definitions that seem to overwrite each other: In[1]:= rowOp[A_?MatrixQ,c_opcode] := (A[[c[[2]]]] = A[[c[[2]]]] c[[3]] /; c[[1]] == 1) In[2]:= rowOp[A_?MatrixQ,c_opcode] := (A[[c[[2]]]] = A[[c[[2]]]] + c[[3]] A[[c[[4]]]] /; c[[1]] == 3) (* We now find the first definition has been overwritten by the second. *) In[3]:= ?rowOp Out[3]= rowOp rowOp/: rowOp[(A_)?MatrixQ, c_opcode] := A[[c[[2]]]] = A[[c[[2]]]] + c[[3]] A[[c[[4]]]] /; c[[1]] == 3 (* If the first definition is now repeated, it in turn overwrites the second definition. *) In[4]:= rowOp[A_?MatrixQ,c_opcode] := (A[[c[[2]]]] = A[[c[[2]]]] c[[3]] /; c[[1]] == 1) In[5]:= ?rowOp Out[5]= rowOp rowOp/: rowOp[(A_)?MatrixQ, c_opcode] := A[[c[[2]]]] = A[[c[[2]]]] c[[3]] /; c[[1]] == 1 In the original source of this problem, the function rowOp had the attribute HoldFirst. The above shows that this is not needed to produce the problem. Changing the name of the pattern c to something else in one or the other definition allows both to coexist. What's going wrong? Any help would be appreciated, Thanks. Lew Lefton Department of Mathematics University of New Orleans New Orleans, Louisiana 70148 Phone: (504) 286-6331 E-mail address: lelma at uno.edu (OR lelma at uno.bitnet)