       Re: Elegant syntax for multiple conditional assignment?

• To: mathgroup at smc.vnet.net
• Subject: [mg54426] Re: [mg54337] Elegant syntax for multiple conditional assignment?
• From: Scott Hemphill <hemphill at hemphills.net>
• Date: Sun, 20 Feb 2005 00:09:40 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```On Sat, 19 Feb 2005, DrBob wrote:

> (inputs)
> old = Array[o, {4}]
> new = Array[n, {4}]
> cond = Array[1 == Random[Integer, {0, 1}] & , {4}]
>
> (outputs)
> {o, o, o, o}
> {n, n, n, n}
> {True, False, True, False}
>
> (input)
>
> (result)
> {n, o, n, o}
>
> or:
>
> old = {a, c, x, y} = Array[o, {4}]
> new = {a, c, x, y} = old^2
> cond = Array[1 == Random[Integer, {0, 1}] &, {4}]
>
> {o, o, o, o}
> {o^2, o^2, o^2, o^2}
> {True, False, False, False}
>
> {a, c, x, y} = Thread[If[cond, Evaluate@new, Evaluate@old]]
>
> {o^2, o, o, o}

This isn't quite what I had in mind.  What I have is more like:

n=100
old={Array[olda,{n}], Array[oldc,{n}], Array[oldx,{n}], Array[oldy,{n}]}
new={Array[newa,{n}], Array[newc,{n}], Array[newx,{n}], Array[newy,{n}]}
cond=Table[Random[Integer]==1,{n}]

Now "a" should be assigned a list whose k'th element is picked from either
olda[[k]] or newa[[k]] depending on cond[[k]], and similarly for c, x, and
y.