MathGroup Archive 2006

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

Search the Archive

Re: ReplaceAll applied to List - solution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72346] Re: ReplaceAll applied to List - solution
  • From: "Hannes Kessler" <HannesKessler at hushmail.com>
  • Date: Tue, 26 Dec 2006 07:23:00 -0500 (EST)
  • References: <em8jdu$pel$1@smc.vnet.net><emb5rq$a22$1@smc.vnet.net>

In order to get my 3rd example working I had to modify it as follows:

{ 1., {2}, 3} /. (x_)?(And[ Not@ListQ@#, Not@MatchQ[#, List] ] &) -> g
--> {g, {g}, g}

Thanks Daniel.

dh schrieb:

> Hi Hannes,
>
> parts of an expression also includes Heads. And a Head can be atomic or
>
> not-a-list.
>
> Daniel
>
>
>
> Hannes Kessler wrote:
>
> > 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: Any simple way to flatten all but the bottom level?
  • Next by Date: Help !! plot roots of an expression
  • Previous by thread: My previous question: solving system of linear equations takes long
  • Next by thread: Help !! plot roots of an expression