Re: ReplaceAll strange behaviour
- To: mathgroup at smc.vnet.net
- Subject: [mg9334] Re: [mg9312] ReplaceAll strange behaviour
- From: jpk at max.mpae.gwdg.de
- Date: Sat, 1 Nov 1997 03:33:22 -0500
- Sender: owner-wri-mathgroup at wolfram.com
> From oron at manet.pmmh.espci.fr Mon Oct 27 15:58:04 1997
> Date: Mon, 27 Oct 1997 02:47:26 -0500
> From: Gadi Oron <oron at manet.pmmh.espci.fr>
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> Subject: [mg9334] [mg9312] ReplaceAll strange behaviour
>
> Hello,
>
> Can anybody enlighten me with the following strange result?
>
> In:= {{1,2},{2,3}} /. {x_ /; Head[x]!=List,y_}:> Circle[{x,y},1] Out:=
> {{1,2},{2,3}}
>
> ???!!!!
>
> Am I missing anything?
Yes, You had used Unequal[] instead of UnsameQ[]. So Your test gives
Integer != List
this is not evaluated furture, this gives not True. The result is, that
the rule never matches. You must use
{{1,2},{2,3}} /. {x_ /;Head[x]=!=List,y_}:> Circle[{x,y},1]
so that You get Integer =!= List, this is evaluated to True and Your
rule match.
A tip, if I found some thing in pattern matching that is not clear at
the first look I add some (Print; test) statements. In Your case
the statement
{{1,2},{2,3}} /.
{x_ /; (Print[Head[x]!=List];Head[x])!=List,y_}:>
Circle[{x,y},1]
gives:
False
Integer != List
Integer != List
Out[112]=
{{1,2},{2,3}}
and shows the mistake clear.
Hope that helps
Jens