[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Of a bad sort: 1 10 2 3 4 5 6 7 8 9



Consider the following list.  Is it sorted?

    1
    2
    10

How about this one:

    1
    10
    2

Most people would say the latter is not sorted.  Yet we continue
to write software that sorts strings this way.  Why do we do it?
Because the available string comparison functions embody a
straightforward, simple implementation--which happens to be wrong
when the sorting of the result is done solely for the convenience
of a user.

I propose that the following functions be added to Common Lisp
so that sorting appropriate for humans can be accomplished
straightforwardly and efficiently:

   human-string<
   human-string>
   human-string<=
   human-string>=
   human-string-lessp
   human-string-greaterp
   human-string-not-greaterp
   human-string-not-lessp

When there is an embedded numeric string at the same position
in both strings, compare those substrings as if they each occupied
a single character position.

Has anyone implemented this in lisp?
Perhaps someone can come up with better names?

Dave Yost