From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Moreton Newsgroups: gmane.emacs.devel Subject: Re: Any interest in a function like this to add to subr.el? Date: Wed, 19 Oct 2016 14:46:02 +0100 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1476885041 19496 195.159.176.226 (19 Oct 2016 13:50:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Oct 2016 13:50:41 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (windows-nt) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 19 15:50:38 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bwrGK-0003xu-Ls for ged-emacs-devel@m.gmane.org; Wed, 19 Oct 2016 15:50:32 +0200 Original-Received: from localhost ([::1]:48722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwrGM-0006IC-Pe for ged-emacs-devel@m.gmane.org; Wed, 19 Oct 2016 09:50:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwrCo-0003Ty-Tk for emacs-devel@gnu.org; Wed, 19 Oct 2016 09:46:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwrCk-0006jx-26 for emacs-devel@gnu.org; Wed, 19 Oct 2016 09:46:54 -0400 Original-Received: from [195.159.176.226] (port=52371 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bwrCj-0006j3-Rk for emacs-devel@gnu.org; Wed, 19 Oct 2016 09:46:49 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bwrCX-0001vH-Of for emacs-devel@gnu.org; Wed, 19 Oct 2016 15:46:37 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 20 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:4UFN1d1aAvlOlpYFSN10kzEVdiw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208473 Archived-At: 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