MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: ReplacePart in an If[] construct?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67851] Re: [mg67834] Re: [mg67816] ReplacePart in an If[] construct?
  • From: gardyloo <gardyloo at mail.wsu.edu>
  • Date: Mon, 10 Jul 2006 06:38:29 -0400 (EDT)
  • References: <NDBBJGNHKLMPLILOIPPOKEBBFBAA.djmp@earthlink.net> <200607090851.EAA24740@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

AND thanks to kalymereau (who sent an alternative pattern-matching
solution), Brian Higgins, and Jens-Pers Kuska. Love the MathGroup!



gardyloo wrote:
>   To all who responded to my question below: Thank you. Especially to
> (so far) David Park, Bob Hanlon, and
> Andrzej Kozlowski.
>   
>> From: gardyloo [mailto:gardyloo at mail.wsu.edu]
To: mathgroup at smc.vnet.net
>>     
> To: mathgroup at smc.vnet.net
>   
>> Hi, all,
>>
>>    It's probably that I'm too tired, but I have a question about using
>> ReplacePart in an If[] construct. I've made up a (very) minimal example:
>>
>> In[1]:=
>> testList = {{3, an, example, list},
>>    {4, another, example, list}}
>>
>> Out[1]=
>> {{3, an, example, list}, {4, another, example, list}}
>>
>> In[2]:=
>> (If[  (ListQ[#1] && First[#1] == 4),
>>     ReplacePart[#1, replaced!, 3];
>>     ReplacePart[#1, replaced!, 2],
>>    #1      (*otherwise*)
>> ] & ) /@ testList
>>
>> Out[2]=
>> {{3, an, example, list}, {4, replaced!, example, list}}
>>
>>
>>         Can someone tell me why BOTH the second and third positions in
>> the second element in testList aren't turned to "replaced!" ?  I have
>> plenty of other ways of doing this, but this seemed the most
>> straightforward, and I can't wrap my head around it, for some reason.
>>
>>   
>>     
>


  • Prev by Date: Re: help with lists operations
  • Next by Date: Re: Repost --- Another limit problem
  • Previous by thread: Re: ReplacePart in an If[] construct?
  • Next by thread: RE: ReplacePart in an If[] construct?