Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Behaviour of Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114852] Behaviour of Replace
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Mon, 20 Dec 2010 00:40:28 -0500 (EST)

Suppose I have this nested list:

demo = {1, {2, {3, {4, {5, {6, {7, {8, 8}}}}}}}}

Replace[demo, {x_, y_} :> {x, a, y}, -1]

Out={1, {2, a, {3, a, {4, a, {5, a, {6, a, {7, a, {8, a, 8}}}}}}}}

I expected to have an a after the 1 too, what I tried to get using

Replace[demo,{x_,y_}:>{x,a,y},-1,Heads->True]

but this gives the same result as above. But this will do what I wanted:

Replace[demo, {x_, y_} :> {x, a, y}, {0, 8}]

Out={1, a, {2, a, {3, a, {4, a, {5, a, {6, a, {7, a, {8, a, 8}}}}}}}}

Can somone please explain this behaviour? What I found was that

Level[demo,{0}] returns {{1},{2,{3...} beeing {demo}

Thank you
-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: switching between versions 7 and 8
  • Next by Date: Counting
  • Previous by thread: Re: switching between versions 7 and 8
  • Next by thread: Re: Behaviour of Replace