On Friday, August 22, 2014 12:05:33 PM UTC+12, mattn wrote:
> > Bug in sort() function?
> 
> See :help sort()
> 
> > The sort is stable, items which compare equal (as number or as...

There is indeed a bug in sort(). The stability of the sort is not relevant.

I haven't been following the thread too closely, but became interested on 
seeing Andy's report of 

    :echo sort(['3 0', '3 0 1'])
    ['3 0 1', '3 0'] 

I tried
    :echo sort(['foo bar','foo'])
    ['foo bar', 'foo']
but 
    :echo sort(['foobar','foo'])
    ['foo', 'foobar']

The space makes a difference, because it sorts less than a single quote.  Try
    :echo sort(['foo','foo&bar','foo(bar'])
    ['foo&bar', 'foo', 'foo(bar']  

Looking in eval.c, to compare list items tv2string is called to stringify each 
item.  tv2string calls string_quote, which puts single quotes around each 
string (and doubles any single quotes in the string).  This effectively adds a 
single quote to the end of each string, and if it's being compared to a string 
that has something comparing less than a quote, it sorts ahead.

I don't know why string_quote is called; it clearly is not useful for this 
purpose, but may be needed for another.

Regards, John Little

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui