Re: Set in Scan
- To: mathgroup at smc.vnet.net
- Subject: [mg21904] Re: Set in Scan
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 4 Feb 2000 02:54:37 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <87aua2$ntf@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, v1 = {0, 0, 0, 0}; v2 = {1, 1, 1, 1}; v3 = {2, 2, 2, 2}; and Scan[Function[v, v[[3]] = newElement, {HoldFirst}], Hold[{v1, v2, v3}], {2}] will work. The point is that Scan[] will evaluate it's second argument and than you can't set the symbol ist lost. That's why you have to use Hold[{v1,v2,v3}]. To Scan the arguments of Hold[] you must set the level in Scan[] explicit. For your pure function you must also prevent the evaluation with an explicit attribute. Hope that helps Jens Johannes Ludsteck wrote: > > Dear MathGroup members > > I have to do replacements in very long lists. An efficient way to do > this is to use > > x[[index]]=newElement. > > This, however, doesn't work if I want to do replacements for a set of > lists. If I try to replace the third element in the lists v1, v2 and v3 by > typing > > Scan[#[[3]] = newElement &, {v1,v2,v3}] > I get the error message > Set::setps: #1 in assignment of part is not a symbol. > > Any suggestions? > Thanks