MathGroup Archive 1998

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

Search the Archive

Re: ReplacePart?



Hi Scott,

I don't think ReplacePart is able to do what you want.

One way to do what you want is to use replacement rules, where the rule
changes each time its used. For example

gt /. {}:>(c=First[b];b=Rest[b];c)

should do the trick. However, this has the side effect of changing b, so
you could make it a function:

ScottReplace1[g_,b_]:=Module[{a,n},
	a = b;
	g /. {}:>(n=First[a];a=Rest[a];n)
]

or even better

ScottReplace2[g_,b_]:=Module[{n},
	n=1;
	g /. {}:>b[[n++]]
]

Carl Woll
Dept of Physics
U of Washington


On Fri, 16 Jan 1998, Scott Morrison wrote:

> I have a list of pairs of the form:
> gt={{3,5},{{},6},{7,{}},{{},{}},{{},56},{{},3}};
> 
> The empty lists inside pairs are being used as placeholders. I want to
> replace these with the elements of b: b={a1,a2,a3,a4,a5,a6};
> hopefully resulting in the list
> {{3,5},{a1,6},{7,a2},{a3,a4},{a5,56},{a6,3}}
> 
> I had thought that ReplacePart could do this, as it says:
> "ReplacePart[expr, new, pos, npos] replaces parts at positions pos in
> expr by
>   parts at positions npos in new."
> 
> 
> I can't get this to work at all. If someone could explain how to do this
> sort of thing, using ReplacePart or otherwise, I would be most
> grateful.
> 
> Scott Morrison
> scott@morrison.fl.net.au
> 
> 
> 
> 




  • Prev by Date: RE: List Manipulation
  • Next by Date: Re: Re: How to learn formatting options
  • Prev by thread: Re: ReplacePart?
  • Next by thread: Re: ReplacePart?