Thanks, everyone. I never understood item-amend until now. That's
exactly what I was looking for. For context, I was reading through the
APL book and hit the "/a,u,b/" notation, and wondered how to do that
in J.

One question though: why is the particular form (result=:c}b,:a)
singled out, rather than the general (c}b,:a)?

On Wed, Dec 21, 2011 at 10:54 AM, Henry Rich <henryhr...@nc.rr.com> wrote:
> Note that
>
> c}b,:a
>
> does indeed compute b,:a.  But if it's used in the precise form
>
> result =: c}b,:a
>
> the computation is avoided.
>
>    b =: 1e6$4
>    a =: 1e6$4
>    c=: ? 1e6$ 2
>    ts 'c}b,:a'
> 0.0401299 2.09725e7
>    ts 'q =: c}b,:a'
> 0.0112949 4.19558e6
>
> There are other special cases; see the Special Code page.
>
> Henry Rich
>
> On 12/21/2011 11:43 AM, Marshall Lochbaum wrote:
>> A more obvious way is to use (c { b,.a) . The key is to realize that saying
>> (if c then a else b) is just selection: if c is 0, we pick b, and if c is
>> 1, we pick a. So we rephrase as (c { b,a), and J's implicit rank allows us
>> to do (c { b,.a) for vector c, a, and b.
>>
>> That said, (c} b,:a) is faster, and uses less memory by not actually
>> computing b,:a . So it's a better choice.
>>
>> Marshall
>>
>> On Wed, Dec 21, 2011 at 10:26 AM, Brian Schott<schott.br...@gmail.com>wrote:
>>
>>> One way is the following.
>>>
>>>    c}b,:a
>>> 10 2 30
>>>
>>>
>>> --
>>> (B=)
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> 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