Re: ReplaceAll strange behaviour
- To: mathgroup at smc.vnet.net
- Subject: [mg9335] Re: [mg9312] ReplaceAll strange behaviour
- From: Olivier Gerard <jacquesg at pratique.fr>
- Date: Sat, 1 Nov 1997 03:33:22 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Bonjour Gadi,
I would be tempted to say, what an original way to do things !
You can for instance use Map, Apply or Thread if you know roughly the
structure or the nesting level of your data. But let's do it with rules
{x_?AtomQ, y_?AtomQ }:>Circle[{x,y},1]
gives what you wanted I believe.
As for the behavior of Replace, it is due to the way you test for the
head of x.
This may look like a moot point but in Mathematica != and == are for
testing *values* of expression, whereas =!= and === test the *form* of
the expression. When the test is applied it gives Integer!=List and
Mathematica cannot decide how to solve this equation because it is for
it as in general any equation a!=b would be, not knowing anything about
the two symbols (when they are utilized isolated, without brackets). As
Mathematica can't solve the equation, the pattern does not match.
If you use
{x_ /; Head[x]=!=List,y_}:> Circle[{x,y},1]
your idea works. So, in general, when testing for heads, use === and
=!=.
But beware, because in your idea, you only test one side. I recommend
looking also at the VectorQ function.
Olivier
At 09:47 +0200 97.10.27, Gadi Oron wrote:
> 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?
>
> Thanx.
> \/\\/\/\/>> Gadi ORON <<\/\/\/\/ o o
> \_____/
> EMAIL : oron at pmmh.espci.fr /=O=O=\ _______
> Soyez braves - Be brave / ^ \ /\\\\\\\\
> \ \___/ / /\ ___ \
> \_ _/ /\ /\\\\ \
> \ \__/\ /\ @_/ /
> \____\____\______/
> Homepage : http://www.pmmh.espci.fr/~oron/personal.html