---Raul Miller wrote:
> Was there anything wrong with my definition for join?
>    join=: [EMAIL PROTECTED] }. [:;,L:0

It's nice and simple,
     join03=: [EMAIL PROTECTED] }. [:;,&.>
Is perhaps slightly clearer and a little faster, but doesn't handle left args 
of length >1.
join04 / join05 seem to have the best combination of performance and features, 
but are not as simple or easy to understand.

a=: '-'
b=: 100000 [EMAIL PROTECTED] 8
c=: (b&(<@{."0 _)) 'abcdefghi'

ts=: 6!:2 , 7!:[EMAIL PROTECTED]

join01=: [: ; [EMAIL PROTECTED] , [: , [EMAIL PROTECTED] ,. [EMAIL PROTECTED]

join02=: [EMAIL PROTECTED] }. [:;,L:0
join03=: [EMAIL PROTECTED] }. [:;,&.>  NB. Use each instead of L:0

join04=: ' '&$. :(4 : '(;@(#^:_1!.(<x))~  1 0$~_1 2 p.#) y')
join05=: 3 : 0  NB. Explicit version of join04
  ' ' join04 y
  :
  (;@(#^:_1!.(<x))~ 1 0$~_1 2 p.#) y
)

     50{.a join01 c
ab-abcd-abcd-abc-ab--ab-abcde-abcde--abc-a-abcd--a

     *./(<a join01 c)-: every a (join02;join03;join04;join05) c
1

     20 ts 'a join01 c'
0.143952 2.91738e6

     20 ts 'a join02 c'
0.0392969 7.8592e6

     20 ts 'a join03 c'
0.0339473 7.85914e6

     20 ts 'a join04 c'
0.0361777 1.83859e6

     20 ts 'a join05 c'
0.0353627 1.83859e6
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to