Re: List Replace Problems
- To: mathgroup at smc.vnet.net
- Subject: [mg59875] Re: List Replace Problems
- From: "dkr" <dkrjeg at adelphia.net>
- Date: Wed, 24 Aug 2005 06:31:56 -0400 (EDT)
- References: <deeom3$3rl$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The first case works because DivideBy has the attribute HoldFirst. The problem with the second case is that the expression that matches u gets immediately substituted inside the Do statement, so you end up evaluating expressions like Do[{1,3,5,7,9}[[i]]/=i,{i,1,5}]. But part assignments are only permitted for values of a symbol, and {1,3,5,7,9} is not a symbol, hence the error message. Try the following: In[83]:= mylst[u_List]:=Fold[ReplacePart[#1,#1[[#2]]/#2,#2]&,u,Range[2,Length[u]]]; a={1,3,5,7,9}; a=mylst[a]; a//InputForm Out[86]//InputForm= {1, 3/2, 5/3, 7/4, 9/5}