Raul's points are valid, but as a technique I like it. I'm going to
add it to my collection of idioms for a monograph on string-handling.

Rotate-and-compare can be generalized to detect any given letter
followed/preceded by some other. But in the speed stakes, there's
often extra housekeeping handling the string ends.

Harking back to a recent thread where (;:inv) came up, how about these too?

wdeb=: ;:inv @ ;:
udeb=: ] &. ;:          NB. a faster variant of the same idea

Not as fast as either deb or fdeb, (besides mishandling punctuation)
but with a certain idiot appeal. And try replacing (]) with (|.),
(~.), sort, etc.

In my monograph, (;:) will have a chapter to itself.


On Wed, Jan 4, 2012 at 1:54 PM, Raul Miller <rauldmil...@gmail.com> wrote:
> As you point out, these are not equivalent.
>
>   # TEST=: '   this   is   a   test   '
> 26
>   # deb TEST
> 14
>   # fdeb TEST
> 15
>
> Note also:
>   # ]&.;: TEST
> 14
>
> That said:
>   # ]&.;: ' Don''t do this... '
> |open quote
>
> Also, the timing difference between 3.446e_6 and 3.293e_6 is inconsequential.
>
> --
> Raul
>
> On Wed, Jan 4, 2012 at 2:14 AM, Alan Stebbens <a...@stebbens.org> wrote:
>> "delete extra blanks" from strings.ijs has this definition:
>>
>>   deb =: #~ (+. (1: |. (> </\)))@(' '&~:)
>>
>> NB. Here is a slightly faster deb:
>>
>>   fdeb =: [ #~ [: -. [: (] *. 1&|.) ' ' = [
>>
>> NB. s is the test string; w is its boxed words
>>
>>   w=.;:s=.'now is the time for all good men to come to the aid of their 
>> country'
>>   w
>> +---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+
>> |now|is|the|time|for|all|good|men|to|come|to|the|aid|of|their|country|
>> +---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+
>>
>> NB. show
>>   1000 tx 'deb ,>w'
>> 3.446e_6 3072
>>
>>   1000 tx 'fdeb ,>w'
>> 3.293e_6 3072
>>
>> NB. same value for both the old and new fun
>>   (deb -: fdeb),>w
>> 1
>>
>> NB. the results match the original string
>>   s -: fdeb ,>w
>> 1
>>
>> However, it's not exactly the same as deb: it doesn't remove a single 
>> leading blank, as does deb (which, IMHO, is not necessarily an "extra" blank 
>> anyway).
>>
>> Alan
>>
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to