There are situations where standard ASCII sorting does not suffice. This egg implements procedures for natural sorting as described on Coding Horror and the linked resources.
- number-re REparameter
Parameter holding an irregex-compatible regular expression used to find a number. Defaults to (+ num), a sequence of at least one numerical digit.
- natural-sort-preprocessor PROCparameter
Parameter holding a preprocessing procedure that adjusts an input string before comparing it to another string. Defaults to identity to leave its input unchanged.
- natural-string<? STRING1 STRING2procedure
- natural-string<=? STRING1 STRING2procedure
- natural-string=? STRING1 STRING2procedure
- natural-string<>? STRING1 STRING2procedure
- natural-string>? STRING1 STRING2procedure
- natural-string>=? STRING1 STRING2procedure
Predicates for comparing two strings according to natural sort order.
- natural-string-compare STRING1 STRING2procedure
Compares two strings according to natural sort order and returns -1 if STRING1 is smaller than STRING2, 0 if STRING1 is equal to STRING2 and 1 if STRING1 is greater than STRING2.
- natural-sort STRINGSprocedure
Convenience procedure for performing a natural sort on a list of strings. It is equivalent to (sort natural-string<? STRINGS).
(import natural-sort) (define (random-ipv4-address) (format "~a.~a.~a.~a" (random 256) (random 256) (random 256) (random 256))) (for-each print (natural-sort (list-tabulate 10 (lambda (_) (random-ipv4-address))))) ;; 18.104.22.168 ;; 22.214.171.124 ;; 126.96.36.199 ;; 188.8.131.52 ;; 184.108.40.206 ;; 220.127.116.11 ;; 18.104.22.168 ;; 22.214.171.124 ;; 250.72.30.164 ;; 250.132.51.35
Copyright (c) 2017, Vasilij Schneidermann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Tests actually run now
- C5 version
- Initial release