Re: conditionnal rule

*To*: mathgroup at smc.vnet.net*Subject*: [mg51515] Re: [mg51499] conditionnal rule*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Thu, 21 Oct 2004 22:20:18 -0400 (EDT)*References*: <200410200521.BAA08454@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On 20 Oct 2004, at 14:21, Wishmaster7 wrote: > > hi all !! > > I want to apply a rule under a certain condition. here is the example : > > myList = {{a, b}, {c, d}}; > > myList //. {a,x_}->{a,d} > > apply this rule if Length[x]===1 (this means that x can not be a list) > > I tried something like : > > myList //. {a_,x_}->{c,d}/;Length[x]===1 > > or > > myList //. {a_,x_?Length[x]===1}->{c,d}/ > > but it does not work. > > can someone help me ? > > Surely, you must have meant Length[x] == 0 not Length[x] == 1 ? You do not need to use ReplaceRepeated here but you do need to use RuleDelayed instead of Rule: myList = {{a, b}, {c, d}}; myList /. {a_, x_} :> {c, d} /; Length[x] == 0 {{c, d}, {c, d}} Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/

**References**:**conditionnal rule***From:*darkness_wizard@hotmail.com (Wishmaster7)