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: Andy Moreton
Subject: Re: Any interest in a function like this to add to subr.el?
Date: Wed, 19 Oct 2016 14:46:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (windows-nt)

On Tue 18 Oct 2016, 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))))))

Doesn't a specialised routine like this belong in subr-x.el ? At least
initially, until it is demonstrated that there is widespread need for it
in emacs core.

    AndyM




reply via email to

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