I'm not sure how useful my opinions are, but here goes:

2011/12/26 Björn Helgason <gos...@gmail.com>:
>   ((a*c)+b*-.c)
> 10 2 30

I think of this as a standard "APL dodge". It's good for numerical
data, if a bit verbose. It feels a bit like a trick; it clearly won't
work for non-numeric data, and I have to explicitly think through how
J handles infinities and NaNs to make sure it does the right thing.

>   <"0 (>c)}(>b),:>a

I don't understand the point of this one. It just boxes the result,
but otherwise seems equivalent to (c}b,:a). In fact, is seems inferior
to (c}b,:a), since it opens b and a, and thus won't work for "generic"
boxed data.

>   c {"_1 b,.a
> 10 2 30

This is what I spent a bit of time searching for, but somehow couldn't
find. It seems like the "natural" way to do this, if you don't know
about "}".

>   (11 _2 p. c) o. a j. b
> 10 2 30

Sneaky and amusing, as intended. It got me to read the documentation
for (p.) and (o.) again. Fails for complex numbers and boxes.

>   (c,&.>i.#c){b,:a
> 10 2 30

I like this one, but I don't find it terribly easy to read. It gives
me another good example of using "{", which I still find pretty
unintuive compared to m[v1;v2]-style indexing.

>   (,c,.-.c)#,a,.b
> 10 2 30

Interesting. This seems pretty general, as far as I can tell. It's a
little ugly to my eyes and feels like it involves extra raveling and
stitching to get the result, mostly because of (,c,.-.c). (I say
"feels like", since I don't have a good intution yet about what
optimizations J performs; many phrases that look like they would
involve extra allocations are optimized away. I'm glad it happens, but
it makes it hard to reason about the code.)

>   c}b,:a
> 10 2 30

This seems the closest to a natural, idiomatic way to do this, so this
is my favorite. Boring, but it doesn't make me jump through hoops.

Those are, at least, my off-the-cuff reactions.

Regards,
-Johann
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to