diff options
Diffstat (limited to 'lisp/sort.el')
| -rw-r--r-- | lisp/sort.el | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/lisp/sort.el b/lisp/sort.el index 4f0d759ef8a..2ee76b6e1e3 100644 --- a/lisp/sort.el +++ b/lisp/sort.el | |||
| @@ -478,27 +478,6 @@ sRegexp specifying key within record: \nr") | |||
| 478 | ;; if there was no such register | 478 | ;; if there was no such register |
| 479 | (error (throw 'key nil)))))))))) | 479 | (error (throw 'key nil)))))))))) |
| 480 | 480 | ||
| 481 | ;;;###autoload | ||
| 482 | (defun sort-on (sequence predicate accessor) | ||
| 483 | "Sort SEQUENCE by calling PREDICATE on sort keys produced by ACCESSOR. | ||
| 484 | SEQUENCE should be the input sequence to sort. | ||
| 485 | Elements of SEQUENCE are sorted by keys which are obtained by | ||
| 486 | calling ACCESSOR on each element. ACCESSOR should be a function of | ||
| 487 | one argument, an element of SEQUENCE, and should return the key | ||
| 488 | value to be compared by PREDICATE for sorting the element. | ||
| 489 | PREDICATE is the function for comparing keys; it is called with two | ||
| 490 | arguments, the keys to compare, and should return non-nil if the | ||
| 491 | first key should sort before the second key. | ||
| 492 | The return value is always a new list. | ||
| 493 | This function has the performance advantage of evaluating | ||
| 494 | ACCESSOR only once for each element in the input SEQUENCE, and is | ||
| 495 | therefore appropriate when computing the key by ACCESSOR is an | ||
| 496 | expensive operation. This is known as the \"decorate-sort-undecorate\" | ||
| 497 | paradigm, or the Schwartzian transform." | ||
| 498 | (mapcar #'car | ||
| 499 | (sort (mapcar #'(lambda (x) (cons x (funcall accessor x))) sequence) | ||
| 500 | #'(lambda (x y) (funcall predicate (cdr x) (cdr y)))))) | ||
| 501 | |||
| 502 | 481 | ||
| 503 | (defvar sort-columns-subprocess t) | 482 | (defvar sort-columns-subprocess t) |
| 504 | 483 | ||