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 23:02:22 -0700 Message-ID: References: <68978e0f-03a3-70ec-c18a-e2d12f91ea5c@yandex.ru> <6d541e6d-f7a1-beba-77f5-94d5a06f93cb@yandex.ru> <3D8D2EC8-5492-4A3B-8766-E27C17C8537A@raeburn.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1476856969 22256 195.159.176.226 (19 Oct 2016 06:02:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Oct 2016 06:02:49 +0000 (UTC) User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (darwin) Cc: Emacs development discussions To: Ken Raeburn Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 19 08:02:43 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 1bwjxW-0004Fg-7F for ged-emacs-devel@m.gmane.org; Wed, 19 Oct 2016 08:02:38 +0200 Original-Received: from localhost ([::1]:45714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwjxY-0002z3-3v for ged-emacs-devel@m.gmane.org; Wed, 19 Oct 2016 02:02:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwjxR-0002yu-Bi for emacs-devel@gnu.org; Wed, 19 Oct 2016 02:02:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwjxM-00080k-W6 for emacs-devel@gnu.org; Wed, 19 Oct 2016 02:02:33 -0400 Original-Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:33740) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bwjxM-00080O-QB for emacs-devel@gnu.org; Wed, 19 Oct 2016 02:02:28 -0400 Original-Received: by mail-pf0-x22e.google.com with SMTP id 128so10133129pfz.0 for ; Tue, 18 Oct 2016 23:02:28 -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:content-transfer-encoding; bh=CHDYe8HDgUNvBvfSo1JTMg180EeSGCRv+9Cea6nEJAg=; b=bVoSvECsnx/ZNIHpGArxovgbFt17/M4YX1TD62UiYnA79wUph5Hvty8jAy7n3v8A/0 k7iW0nBTfnuhbsYDFZeX2mriOpRONUN/NBcAyrucop2xMSRjP+lwhD2SmlUu8UGQvG/Z QGAx71btfc2Emi+ltRFYIS61rkli+Xbn6RphjM79dsLDj/uK4G14Pm5+vbZP9m+PJ76i Oe2AdTKanfTGn4YnChMkozYA/0xIeGQw8blFB4kiFhmg20WhpiArMlFtySPI/AflufrG GXorHLJBNS3VF3wwpII9y9mt4qxkCnh3bwt5f+oQIYApT47Qlg+6YDbngRTIIONdh9mO 4BsA== 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 :content-transfer-encoding; bh=CHDYe8HDgUNvBvfSo1JTMg180EeSGCRv+9Cea6nEJAg=; b=fKlQa4cz+GpZjKOhzPfY7vbFt5ZG7k9Es/kH8jll31yEDxgCJjtIGCDyF7D3HQa1+Y dLK5P7nTxN7qlF1gITklwlRTSshwfpJ7G4o4JbhRUIuK5XP91Dto9gVphD2W1NSdIG8F Lyuinw7tpE+M7moM09wQ85Hh7+Tu0JQgP41XYufR4IbPlKwddMxFHSH6F/7OFNMhRGiW 4Rr5b3VjjuoGMoOy5e9/6kyvH/xI0H9EIpSpsAIebR+HmqNt4F4mM9x2zScZIPapwkbQ sVCbypARTumtfP/csI48PfbV1ZGz3xCRVERGXxBbO2dy6JSljMYlfPbi9+7JqA8k3b8x nVKQ== X-Gm-Message-State: AA6/9RmZrF/kTA6EMQ1BHXJNFrCEHn3CzbcI9IdyEuB14cHrSx813mDKYuLa1T4s9fDnnQ== X-Received: by 10.99.237.69 with SMTP id m5mr6438751pgk.113.1476856947316; Tue, 18 Oct 2016 23:02:27 -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 xv9sm60309379pab.36.2016.10.18.23.02.26 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 18 Oct 2016 23:02:26 -0700 (PDT) X-Google-Original-From: "John Wiegley" Original-Received: by Vulcan.local (Postfix, from userid 501) id 845A030AD845; Tue, 18 Oct 2016 23:02:26 -0700 (PDT) In-Reply-To: <3D8D2EC8-5492-4A3B-8766-E27C17C8537A@raeburn.org> (Ken Raeburn's message of "Wed, 19 Oct 2016 01:01:36 -0400") Mail-Followup-To: Ken Raeburn , Emacs development discussions X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22e 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:208454 Archived-At: >>>>> Ken Raeburn writes: > Is there a shorthand function for this bit? I.e., mutate every element of > the list according to some supplied function, but reusing the same list > storage. If so, the body of sort-on* becomes about as short as your origi= nal > sort-on. I'd like that too. > Is there any benefit to sort* instead of sort here? As far as I can see, > sort* just calls sort after (1) checking whether the list we just iterated > over is a list, and (2) checking whether we supplied a =E2=80=9C:key=E2= =80=9D keyword, which > we didn=E2=80=99t. You're right, I should just use sort. > =E2=80=9Csort=E2=80=9D and =E2=80=9Csort*=E2=80=9D will work on vectors, = too, returning the now-sorted > vector; your sort-on, using mapcar, will make it into a list, and sort-on* > will fail trying to apply car and cdr to vectors. Were these intended to > work on lists only? It should be generalized to work for vectors as well. > As far as your doc strings go, you say sort-on will apply the accessor = =E2=80=9Cat > most once per element in the list=E2=80=9D, but it=E2=80=99s going to be = exactly once per > element, isn=E2=80=99t it? Correct. > The =E2=80=9Ccdr=E2=80=9D pass before returning could walk the intermedia= te sorted list in > the sort-on case too, making it more space-efficient. Since the inner > =E2=80=9Cmapcar=E2=80=9D call has allocated us some unshared storage, we = can just alter it > in place and return it to the caller. Great observation, I'll do that! Thanks for the valuable feedback, --=20 John Wiegley GPG fingerprint =3D 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2