Having looked a little more carefully at the two
posts below by Roger and by Oleg, I have become aware of
some subtleties that I would like to mention. Roger's verb
bsort uses conjunctions agenda (@.) and self-reference ($:)
.
Implicitly Oleg has revamped bsort into bsort1 and
then into bsort2 as shown below. The transition from bsort
to bsort1 mostly replaces the conjunction agenda with the
conjunction power and in doing so reinforces for me how
similar those to conjunctions are, at least in some cases.
Whereas I think of power as being a sort of iteration, when
used in this way, power facilitates recursion.
The transition from bsort1 to bsort2 is primarily a
slight of hand to use a pair of hooks in place of a pair
of forks, but is quite elegant, also.
bsort =: ] ` ((=<./) (# , [: $: [EMAIL PROTECTED] # ]) ]) @. (1<#)
bsort1=: ((=<./) (# , [: $: [EMAIL PROTECTED] # ]) ]) ^: (1<#)
bsort2=: ((#~ , ($:@#~ -.)) (= <./)) ^: (1<#)
I am still working on understanding how Oleg's verb
cap, when added to bsort2, is able to capture the key
information from the recursion into A which is finally
displayed so plainly in the view verb, which has its own
beauty. Thanks to all for this thread.
(B=)
On Mon, 28 Apr 2008, Roger Hui wrote:
bsort=: ] ` ((=<./) (# , [: $: [EMAIL PROTECTED] # ]) ]) @. (1<#)
On Mon, 28 Apr 2008, Oleg Kobchenko wrote:
Note why Roger's picture looked different:
this algorithm uses recursion and we only captured
the tail of it, so the resulting heads were those items
disapearing from previous step.
Here's fully captured steps.
cap=: [ 3 : 'A=:A,<y'
A=: ''
(([EMAIL PROTECTED] , ($:@#~ -.)) (= <./))@cap ^: (1<#) C
0 0 2 4 4 5 6 7 9 9
view }:,~&>/ 7({. ,: a:,(<@;\@|[EMAIL PROTECTED])) A
+---------+---------+---------+---------+---------+---------+---------+
|****** | | | | | | |
|***** | | | | | | |
|*********|****** |** |** |** |** |** |
|** |***** |****** |**** |**** |**** |**** |
|**** |*********|***** |**** |**** |**** |**** |
|*********|** |*********|****** |***** |***** |***** |
| |**** |**** |***** |****** |****** |****** |
|******* |*********|*********|*********|*********|*********|******* |
| |******* |******* |*********|*********|*********|*********|
|**** |**** |**** |******* |******* |******* |*********|
+---------+---------+---------+---------+---------+---------+---------+
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm