2007/6/10, Raul Miller <[EMAIL PROTECTED]>:
On 6/9/07, June Kim <[EMAIL PROTECTED]> wrote:
> I'd appreciate any suggestion for improvement -- better and more
> elegant approaches.
Perhaps we should start by contrasting with a pattern such as
(rv/.~kv)
where kv is your key verb and rv is your result verb.
For example if I take your first example, and try to write what
I think you described, I might eliminate the key verb entirely
and just write:
(;~~.)/.~ 'aaaabbaacc'
+-+------+
|a|aaaaaa|
+-+------+
|b|bb |
+-+------+
|c|cc |
+-+------+
And I notice that I got a different result than you -- one more in
line with what SQL does with GROUP BY. If I want the effect
of Unix's uniq, I can use a key verb
unikey=: +/\@([EMAIL PROTECTED] {. 2~:/\])
This is beautiful.
((;~~.)/.~ unikey) 'aaaabbaacc'
This isn't very complicated but it get's fairly complicated dealing
with another example I gave:
( (# ;~ >@{.@;:@>@{.) /.~ [: unikey >@{.@;: each) d
+-+----+
|a|aaaa|
+-+----+
|b|bb |
+-+----+
|a|aa |
+-+----+
|c|cc |
+-+----+
Anyways, /.~ captures most of the concept of GROUP BY, is simple
to type, and leaves the complexities to the specific cases which
need that complexity. This, I think, is the right way to approach
these sorts of analogies.
I love key(/.) but sometimes I need the behavior of unix's uniq.
Thank you.
But if I am missing your point, let me know.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm