[Jprogramming] choosing between alternates (iif, ifelse)
Linda Alvord
lindaalvord at verizon.net
Thu Dec 22 10:25:03 HKT 2011
Based on the previous message, is this what you are looking for?
<"0 (>c2)}(>b2),:>a2
---T-T--┐
│10│2│30│
L--+-+---
Linda
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] On Behalf Of Johann Hibschman
Sent: Wednesday, December 21, 2011 10:15 AM
To: programming at jsoftware.com
Subject: [Jprogramming] choosing between alternates (iif, ifelse)
(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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list