Re: Re: ReplacePart question

• To: mathgroup at smc.vnet.net
• Subject: [mg13199] Re: [mg13100] Re: ReplacePart question
• From: Wouter Meeussen <w.meeussen.vdmcc at vandemoortele.be>
• Date: Mon, 13 Jul 1998 07:42:48 -0400
• Sender: owner-wri-mathgroup at wolfram.com

hi,

while we're waiting for a new version of Mathematica, (;-)) something
can be thrown together on the basis of "Fold":

FoldList[
ReplacePart[#1,{u, x , y ,z},#2[[1]],#2[[2]]]&,
{a,b,c,d},{ {{1},2},  {{4}, 1}}]
Out[17]=
{{a, b, c, d}, {x, b, c, d}, {x, b, c, u}}

*** function definition ***

myReplaceParts[
expr_List,
new_List,
targetpointers_List,
sourcepointers_List]:=
Fold[
ReplacePart[#1,new,#2[[1]],#2[[2]]]&,
expr,
Transpose[{targetpointers,sourcepointers}]
]

*** testing & demo  ***

In[36]:=
myReplaceParts[{a,b,c,d,e,f},
{u,v,w,x,y,z},
{ {1}, {{3},{2}}, {5} },
{1,2,3}]
Out[36]=
{u, v, v, d, w, f}

enjoy,

wouter.

At 03:44 07.07.98 -0400, you wrote:
>Walter Seaman wrote in message <6nkvd3\$17k at smc.vnet.net>...
>
>>For example, suppose I want to take the list
>>{a,b,c,d} and replace a with y and x with b.  It seems I should be able
>>to use the command
>>
>>ReplacePart[{a, b, c,d},{x,y},{{1},{4}},{2,1}]
>>
>>but the output is
>>{{x,y}\[LeftDoubleBracket]2,1\[RightDoubleBracket],b,
>>  c,{x,y}\[LeftDoubleBracket]2,1\[RightDoubleBracket]}
>>

clip

>
>Paul A. Rombouts <paromb at worldonline.nl>
>________________________________________________________________________
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>Hello Paul,
>
>What you want to do is not possible in V3.0.x.  You will have to replace
>the parts individually and use a sequence of ReplaceParts commands:
>
>In[51]:= ReplacePart[{a,b,c},{d,e,f},1,2] Out[51]= {e,b,c}
>
>I have been told that the ablility to replace multiple parts will be
>available in the next major release (i.e. 3.1).
>
>Tom Zeller
>Wolfram Research Technical Support - Student Versions
>
>________________________________________________________________________
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>
>
>

NV Vandemoortele Coordination Center Oils & Fats Applied Research
Prins Albertlaan 79
Postbus 40
B-8870 Izegem (Belgium)
Tel: +/32/51/33 21 11
Fax: +/32/51/33 21 75
vdmcc at vandemoortele.be

• Prev by Date: Re: coordinate transformation
• Next by Date: Re: Starting Sound in Mathematica for Windows
• Previous by thread: Re: ReplacePart question
• Next by thread: RE: Re: Re: Maximize