On Sun, Aug 24, 2008 at 11:22 AM, Robert Webb wrote: > > Hi, > > The help for sort() says the following with respect to the function > reference argument: > > ...The function is invoked with two > items as argument and must return zero if they are equal, 1 if > the first one sorts after the second one, -1 if the first one > sorts before the second one. Example: > func MyCompare(i1, i2) > return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 > endfunc > > Does it really have to return -1, 0, or 1? Or is it OK to just return > negative, 0 or positive?
It's OK to just return Negative, Zero, or Positive, according to C89. > That way it becomes easier: > > func MyCompare(i1, i2) > return a:il - a:i2 > endfunc But, this is not valid for all i1 and i2, even discounting floats: :let i1 = 2147483647 :let i2 = -1 :echo i2 - i1 " Returns -2147483648 :echo i1 - i2 " Returns -2147483648 Using your comparator, -1 < 2147483647 and 2147483647 < -1. ~Matt --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---