Thanks to both of you who posted in response. I think I have a
reasonable understanding of forks and hooks, but in this case I didn't
realize the way that (+,-) would work. Until I worked through a few
examples I didn't understand why it was giving me what I wanted, not
because I didn't understand forks, but because I wasn't following the
(simple) math. <sigh>
On Feb 1, 2008, at 3:52 AM, Arie Groeneveld wrote:
What could be converted e.g. to (less ugly?)
v=: [:/:[EMAIL PROTECTED]|@(+,-)/
I ended up with
f=: [: /:~ [: ~. [: | ~.@:(+ , -)/
I added a nub atop the fork, and that makes it remove duplicates as it
goes along. It now handles lists up to several hundred numbers long in
a reasonable time.
I was able to similarly modify your prettier version to this:
v=: [:/:[EMAIL PROTECTED]|@~.@:(+,-)/
and now it handles larger lists as well. One thing I _don't_
understand is how you tell when you need @ and when you need @: and
when you need nothing. So in my example, | is capped (straight from
the 13 :) but in your version there is nothing between the | and the
~. to its left. I have no clue why nothing is necessary there.
Further, I don't understand why I needed @: between ~. and the left
parenthesis instead of @ alone. I just know one worked and the other
didn't ;-)
regards,
Geoff
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm