From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Wiegley Newsgroups: gmane.emacs.devel Subject: Re: Any interest in a function like this to add to subr.el? Date: Tue, 18 Oct 2016 14:25:14 -0700 Message-ID: References: <68978e0f-03a3-70ec-c18a-e2d12f91ea5c@yandex.ru> <6d541e6d-f7a1-beba-77f5-94d5a06f93cb@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1476825968 14847 195.159.176.226 (18 Oct 2016 21:26:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 18 Oct 2016 21:26:08 +0000 (UTC) User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (darwin) Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 18 23:26:00 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 1bwbtA-0008HA-8r for ged-emacs-devel@m.gmane.org; Tue, 18 Oct 2016 23:25:36 +0200 Original-Received: from localhost ([::1]:44029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwbtC-0003PD-E3 for ged-emacs-devel@m.gmane.org; Tue, 18 Oct 2016 17:25:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwbsy-0003NP-DK for emacs-devel@gnu.org; Tue, 18 Oct 2016 17:25:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwbst-0006tE-FJ for emacs-devel@gnu.org; Tue, 18 Oct 2016 17:25:24 -0400 Original-Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:36203) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bwbst-0006sF-8m for emacs-devel@gnu.org; Tue, 18 Oct 2016 17:25:19 -0400 Original-Received: by mail-pf0-x231.google.com with SMTP id e6so2850346pfk.3 for ; Tue, 18 Oct 2016 14:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:date:message-id:references :user-agent:mail-followup-to:mime-version; bh=sHK9wY+6L0nTfojhW53gUGk7f9POaDUDQHroFZMJRp0=; b=DR6Hf2EXH6VQ38A9EYSiLuuYB3oZg3dZJhFnnGwGkTBdphIP59hUYUtPivn70y9LIF 0n0KdQyQtRQBrA3hI1NxTZ4ZvE6/o+SpyG6QWbpiu6jQA6uZ5bfUO7Yz6xO9e2lOR2kp 2sjFO8sQVk/LvDD2nsyCNZpvgW9OXet2vEH54nyyGg7CbaolWoZtMy+0C0d76ZrVJD5Q uX4cp16YgB2XuWBmUuwx6uW+xJYvMhayriBZcQtU258KGs5UeMV0sDOeQ+kL/H6Lw5wI HDDZdRZk5ZPB4/L12Di+7RKM4ewhwVDjz+n9fO98+P2ssB018ta7AdcOSdicL2MA1dKo UWUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:in-reply-to:date:message-id :references:user-agent:mail-followup-to:mime-version; bh=sHK9wY+6L0nTfojhW53gUGk7f9POaDUDQHroFZMJRp0=; b=G1BuERs64E47s0t9BJ89DoFa2uEXyyA+7CC8Kc2ZICatQBeSBfdPUQJaUFMh/wibjy NIEoVwCFiVeCqu2wCHWZhTsK31rfzJwGrO+989CF+vU5WOnVxfaco232MrgesjH/f0Oz Ks3kZn9nFQR0X/cshmxPL/pWNeLvvr54KCiey91fRliPg1bMWEWLuVQZ+ARHryeflPfq 6b8owimvszld98YvOYh381k5q+86g8dkcQDVpOILTkteMwbgmYg9JgEtixDr52BhAY0M 3LuN0RtPUgqXCAEaeKtg3t5MG72hjhZpFsnPY501WOuf9XYl6jjA/lfbXC3XYLB1B3OS iCzQ== X-Gm-Message-State: AA6/9Rn/md0vAXk8PfZao7Nff668thD5H2C9zlKf55Ihn8IIwS8A1fQwDWFJCyKBwgRoDA== X-Received: by 10.98.66.149 with SMTP id h21mr4320584pfd.32.1476825918272; Tue, 18 Oct 2016 14:25:18 -0700 (PDT) Original-Received: from Vulcan.local (76-234-69-149.lightspeed.frokca.sbcglobal.net. [76.234.69.149]) by smtp.gmail.com with ESMTPSA id w15sm58118871pfi.47.2016.10.18.14.25.17 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 18 Oct 2016 14:25:17 -0700 (PDT) X-Google-Original-From: "John Wiegley" Original-Received: by Vulcan.local (Postfix, from userid 501) id 918E930AADAF; Tue, 18 Oct 2016 14:25:17 -0700 (PDT) In-Reply-To: <6d541e6d-f7a1-beba-77f5-94d5a06f93cb@yandex.ru> (Dmitry Gutov's message of "Wed, 19 Oct 2016 00:09:02 +0300") Mail-Followup-To: Dmitry Gutov , emacs-devel@gnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::231 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:208452 Archived-At: >>>>> "DG" == Dmitry Gutov writes: GD> Then I agree that we want a function like that. We'd want a destructive GD> version of it as well, though. Yes, good idea! How about something like this: (defun sort-on* (seq predicate accessor) "Sort SEQ using PREDICATE applied to values returned by ACCESSOR. This is a destructive version of `sort-on', which attempts to reuse storage as much as possible." (let ((seq2 seq)) (while seq2 (setcar seq2 (cons (funcall accessor (car seq2)) (car seq2))) (setq seq2 (cdr seq2)))) (setq seq (sort* seq #'(lambda (x y) (funcall predicate (car x) (car y))))) (let ((seq2 seq)) (while seq2 (setcar seq2 (cdar seq2)) (setq seq2 (cdr seq2))) seq)) -- John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2