emacs-devel
[Top][All Lists]
Advanced

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

Re: Any interest in a function like this to add to subr.el?


From: Dmitry Gutov
Subject: Re: Any interest in a function like this to add to subr.el?
Date: Tue, 18 Oct 2016 23:13:59 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Thunderbird/50.0

On 18.10.2016 20:53, John Wiegley wrote:
(defun sort-on (seq predicate accessor)
  "Sort SEQ use PREDICATE applied to values returned by ACCESSOR.
This implements the so-called Schwartzian transform, which has
the performance advantage of applying ACCESSOR at most once per
element in the list, as opposed to using `sort' with a PREDICATE
that applies the ACCESSOR.
Note: this function is only a win over `sort' if ACCESSOR is
compute-intensive; otherwise, it uses more intermediate cons
cells than regular `sort', and so represents a memory for CPU
tradeoff."
  (mapcar #'cdr (sort (mapcar #'(lambda (x) (cons (funcall accessor x) x)) seq)
                      #'(lambda (x y) (funcall predicate (car x) (car y))))))

Isn't this basically cl-sort, though?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]