MathGroup Archive 2006

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

Search the Archive

Re: ReplaceAll applied to List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72442] Re: ReplaceAll applied to List
  • From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
  • Date: Thu, 28 Dec 2006 04:55:50 -0500 (EST)
  • References: <emti1h$krd$1@smc.vnet.net>

You need to restrict the level to which the replacements are applied.

Replace[{1., {2}, 3}, x_?AtomQ :> g,1]

gives

{g,{2},g}

Steve Luttrell
West Malvern, UK

"Hannes Kessler" <HannesKessler at hushmail.com> wrote in message 
news:emti1h$krd$1 at smc.vnet.net...

> Hello,
>
> I want to apply transformation rules to those elements of a list which
> are not lists themselves. The structure of the list is unknown in
> advance.
>
> The following simple examples illustrate my my problems with ReplaceAll
> and List:
>
> Expected result:
> {1., {2}, 3} /. x_?NumericQ :> g
> --> {g,{g},g}
>
> Unexpected result - inspite of AtomQ[{1., {2}, 3}] giving False
> {1., {2}, 3} /. x_?AtomQ :> g
> --> g[g, g[g], g]
>
> Similarly unexpected result - inspite of Not[ListQ[{1., {2}, 3}]]
> giving False
> {1., {2}, 3} /. x_?(Not[ListQ[#]] &) :> g
> --> g[g, g[g], g]
>
> Any explanations for this behavior?
>
> Thanks in advance,
> Hannes Kessler
> 



  • Prev by Date: RE: Bug or feature ?
  • Next by Date: Re: latex label in mathematica graphics
  • Previous by thread: ReplaceAll applied to List
  • Next by thread: RealTime3D