[Jprogramming] String sort, possible bug

David Mitchell davidmitchell at att.net
Fri Mar 13 14:19:26 UTC 2020


This is documented (see Rank sentence in the doc):

https://code.jsoftware.com/wiki/Vocabulary/slashco#dyadic

The order of priority for ordering-up is:

     Type: numeric or empty, symbol, character (byte or unicode), and boxed, are 
so ordered
     Rank: lower comes before higher
     Values: compared after padding with fills to the same shape
         Symbols are compared based on their symbol index, not the character 
lists they represent.

Cheers,
David

On 3/13/2020 01:19, 'Jon Hough' via Programming wrote:
> Consider the wrods:
> 
>     words =: 'a';'z';'zza';'abc';'zabc';'abbb'
>     sort words
> ?????????????????????????????????????????????????????????????????????
> ???a???z???abbb???abc???zabc???zza???
> ?????????????????????????????????????????????????????????????????????
> 
> the sorted words are not correctly (lexicographically) sorted.
> 
> If I replace 'z' with 'z ' (space after z character)
>   words =: 'a';'z ';'zza';'abc';'zabc';'abbb'
>     sort words
> ????????????????????????????????????????????????????????????????????????
> ???a???abbb???abc???z ???zabc???zza???
> ????????????????????????????????????????????????????????????????????????
>     
> the strings are correctly sorted.
> It seems sort has trouble with single character strings.
> Is this a bug, or am I misunderstanding sort with strings?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 


More information about the Programming mailing list