From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Demetrios Obenour Newsgroups: gmane.emacs.bugs Subject: bug#16963: A patch to create a list-with-tail primitive. Date: Sat, 29 Mar 2014 09:30:56 -0400 Message-ID: <1396099856.8469.3.camel@localhost.localdomain> References: <1394200708.1710.4.camel@localhost.localdomain> <5330EDB0.1070406@dancol.org> <1395963445.1956.2.camel@localhost.localdomain> <5334B66A.1040908@dancol.org> <1396057618.8469.0.camel@localhost.localdomain> <53362659.8030106@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1396099957 21320 80.91.229.3 (29 Mar 2014 13:32:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 29 Mar 2014 13:32:37 +0000 (UTC) Cc: 16963@debbugs.gnu.org To: Daniel Colascione Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 29 14:32:29 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WTtN2-0000Qe-S6 for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Mar 2014 14:32:25 +0100 Original-Received: from localhost ([::1]:39372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTtN2-0001fs-ED for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Mar 2014 09:32:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTtMr-0001eh-9L for bug-gnu-emacs@gnu.org; Sat, 29 Mar 2014 09:32:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTtMi-0007Ti-R6 for bug-gnu-emacs@gnu.org; Sat, 29 Mar 2014 09:32:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTtMi-0007Ta-NP for bug-gnu-emacs@gnu.org; Sat, 29 Mar 2014 09:32:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WTtMh-0002dZ-0y for bug-gnu-emacs@gnu.org; Sat, 29 Mar 2014 09:32:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Demetrios Obenour Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Mar 2014 13:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16963 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 16963-submit@debbugs.gnu.org id=B16963.13960998688080 (code B ref 16963); Sat, 29 Mar 2014 13:32:02 +0000 Original-Received: (at 16963) by debbugs.gnu.org; 29 Mar 2014 13:31:08 +0000 Original-Received: from localhost ([127.0.0.1]:55530 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WTtLl-000256-UV for submit@debbugs.gnu.org; Sat, 29 Mar 2014 09:31:07 -0400 Original-Received: from mail-yh0-f46.google.com ([209.85.213.46]:54051) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WTtLe-00020G-LM for 16963@debbugs.gnu.org; Sat, 29 Mar 2014 09:30:59 -0400 Original-Received: by mail-yh0-f46.google.com with SMTP id b6so6043885yha.5 for <16963@debbugs.gnu.org>; Sat, 29 Mar 2014 06:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version:content-transfer-encoding; bh=ZEm6+av7oMtNed8VSe1Bdbaisu3qZ6dNDQGbftjQzHk=; b=X5dLe9K9oST7PriI2YHMQBrnzte+5nBi0Xiwl9e16hZ5Y/vdHI5rbqKPnhhq2Vpot5 tjKBM4Z7COV18jljE06juGhwQoFJ5ux7NXj241VYllfU5Y6+c+eNeCs0ULLeUKEBdcoh /jHM8IbCpiE8K/SSASXlFQhFNRQpLoDHCfP4tahYKjo4/Ly5KpDrI486CLidsWm96cwU VFZgJyT4HPsukmIQ0QXTXzT4cRkHd+9Cg8+sw6Q6xmSY3nQucba6YF7SThQPVAVQedj5 hCRfahxL0DBVvOzuxk2s5j4Jet5Qd+APblixyohzYZamnwGh78NtnZWAM5dzbOA9eIh6 6Lrw== X-Received: by 10.236.203.101 with SMTP id e65mr814876yho.156.1396099857749; Sat, 29 Mar 2014 06:30:57 -0700 (PDT) Original-Received: from [192.168.200.131] (c-71-236-63-161.hsd1.tn.comcast.net. [71.236.63.161]) by mx.google.com with ESMTPSA id t44sm14219926yhc.6.2014.03.29.06.30.56 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Sat, 29 Mar 2014 06:30:57 -0700 (PDT) In-Reply-To: <53362659.8030106@dancol.org> X-Mailer: Evolution 3.10.4 (3.10.4-2.fc20) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:87522 Archived-At: On Fri, 2014-03-28 at 18:48 -0700, Daniel Colascione wrote: > On 03/28/2014 06:46 PM, Demetrios Obenour wrote: > > On Thu, 2014-03-27 at 16:38 -0700, Daniel Colascione wrote: > >> On 03/27/2014 04:37 PM, Demetrios Obenour wrote: > >> > On Mon, 2014-03-24 at 19:45 -0700, Daniel Colascione wrote: > >> >> On 03/24/2014 07:10 PM, Stefan wrote: > >> >>>> Since a comment in backquote.el said that backquote-list* needed to be a > >> >>>> primitive, here is an implementation of it as one, under the name > >> >>>> list-with-tail. > >> >>> > >> >>> I think it would make more sense to call it `list*'. Also it might make > >> >>> sense to change backquote.el so it uses this `list*' (tho probably only > >> >>> when passed with enough arguments). > >> >> > >> >> Agreed. On more that one occasion, I've wished we had a CL-less `list*'. > >> >> If you do add this feature, please make sure the existing list* compiler > >> >> macros keep working. > >> >> > >> > What about just deleting these compiler macros, and making cl-list* an > >> > alias for list*? > >> > > >> > There seems to be little point in keeping them if list* is a primitive. > >> > >> The new list* doesn't have an opcode, but cons does. > >> > > Good point! My testing showed four nested cons calls to be much faster > > than list* with five arguments by several dozen times. > > > > Maybe list* should be a macro instead? > > No, list* as a function is perfectly fine --- we might want to call it > indirectly sometimes, e.g., with apply. The compiler macro is sufficient > to convert it to cons calls when we know it's safe. M-x disassemble is > your friend. :-) > Ah thanks! Here is a patch to fix the Lisp files to exploit a list* primitive. === modified file 'lisp/emacs-lisp/cl-lib.el' --- lisp/emacs-lisp/cl-lib.el 2014-01-01 07:43:34 +0000 +++ lisp/emacs-lisp/cl-lib.el 2014-03-29 13:12:10 +0000 @@ -527,19 +527,13 @@ ;; (while (consp (cdr x)) (pop x)) ;; x)) -(defun cl-list* (arg &rest rest) +(defalias 'cl-list* (symbol-function 'list*) "Return a new list with specified ARGs as elements, consed to last ARG. Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to `(cons A (cons B (cons C D)))'. -\n(fn ARG...)" - (declare (compiler-macro cl--compiler-macro-list*)) - (cond ((not rest) arg) - ((not (cdr rest)) (cons arg (car rest))) - (t (let* ((n (length rest)) - (copy (copy-sequence rest)) - (last (nthcdr (- n 2) copy))) - (setcdr last (car (cdr last))) - (cons arg copy))))) +\n(fn ARG...)") +(put 'list* 'compiler-macro #'cl--compiler-macro-list*) +(put 'cl-list* 'compiler-macro #'cl--compiler-macro-list*) (defun cl-ldiff (list sublist) "Return a copy of LIST with the tail SUBLIST removed." === modified file 'lisp/emacs-lisp/cl.el' --- lisp/emacs-lisp/cl.el 2014-01-01 07:43:34 +0000 +++ lisp/emacs-lisp/cl.el 2014-03-29 12:58:27 +0000 @@ -257,7 +257,6 @@ adjoin copy-list ldiff - list* cddddr cdddar cddadr