To sum it up I think these are the ways that give the results you want

   a=: 10 20 30
   b=: 1 2 3
   c=: 1 0 1
   ((a*c)+b*-.c)
10 2 30
   <"0 (>c)}(>b),:>a
┌──┬─┬──┐
│10│2│30│
└──┴─┴──┘
   c {"_1 b,.a
10 2 30
   (11 _2 p. c) o. a j. b
10 2 30
   (c,&.>i.#c){b,:a
10 2 30
   (,c,.-.c)#,a,.b
10 2 30
   c}b,:a
10 2 30

And may of course be more.

Which one do you like?

2011/12/21 Johann Hibschman <jhibsch...@gmail.com>

> (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
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to