There's a lot of special code already for those functions:
stg =: 'abcdefghijklmnopqrstuvwxyz' {~ 1e6 ?@$ 26
ssdir =: I.@(= {.),.#;.1
ssdir2 =: (I.@:= {.) ([ ,. (2&(-~/\))@:,) #
(ssdir -: ssdir2) stg
1
ts 'ssdir stg'
0.00941909 1.57376e6
ts 'ssdir2 stg'
0.00465763 1.31168e6 NB. No big deal, both are pretty fast
ssndx=: [: ; (<@:{~ (+i.)/)"1~
ssndx2 =: (;@:(<;.0)~ ,."1)~
ndx =. (10 * i. 10000) ,. 5
ndx (ssndx -: ssndx2) stg
1
ts 'ndx ssndx stg'
0.028582 2.58368e6
ts 'ndx ssndx2 stg'
0.000240439 656448 NB. Wow
Henry Rich
On 9/21/2011 9:45 PM, Raul Miller wrote:
> On Wed, Sep 21, 2011 at 9:12 PM, June Kim (김창준)<[email protected]> wrote:
>> To some people, numerical computation and handling isn't too
>> attractive. They are more interested in string manipulation.
>
> For what it's worth: I spent about 10 years working on text
> manipulation programs in APL. And I started by debugging race
> conditions on them in a multi-user environment. (Which means not just
> reading them but discovering subtle, non-reproducible issues in other
> people's code.)
>
> So, anyways, I am of the opinion that APL and J are rather nice for
> text manipulation.
>
> That said, I rather miss a couple utilities from APL which no one has
> seen cause to re-implement in J:
>
> ssdir and ssndx
>
> ssdir=: I.@(= {.),.#;.1
> ssndx=: [: ; (<@:{~ (+i.)/)"1~
>
> ssdir '/abcd/efg/hijkl'
> 0 5
> 5 4
> 9 6
> (1 4,:~6 3) ssndx '/abcd/efg/hijkl'
> efgabcd
>
> and, of course, as I have just now demonstrated, they can easily be
> represented in J. But the apl versions I was using were hand-coded
> assembly language so they were very fast, and in J they are slow
> enough it's usually better to just use the underlying operations
> directly.
>
> Anyways... J is quite nice, in my opinion, for text handling. In some
> contexts perl or bash can be nicer, but not always.
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm