[Jprogramming] choosing between alternates (iif, ifelse)
Johann Hibschman
jhibschman at gmail.com
Wed Dec 21 23:14:59 HKT 2011
(I'm re-sending this, since I think I had my list subscription
mis-configured. Hopefully, no one is getting this twice.)
What's the J idiom for choosing between alternates, based on a boolean
vector? In other languages, this is called something like "iif" or
"ifelse".
If I have:
a=: 10 20 30
b=: 1 2 3
c=: 1 0 1
I want to get (10 2 30).
I can get this by something like ((a*c)+b*-.c), but that breaks if a
and b are boxes. For example, with
a2=:10;20;30
b2=: 1;2;3
then that trick doesn't work. Is there a more direct way? I tried
looking for this in the Phrases, but I couldn't find it there. There
was a merge, but that was a more complex operation.
Regards,
Johann
More information about the Programming
mailing list