unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Demetrios Obenour <demetriobenour@gmail.com>
To: Daniel Colascione <dancol@dancol.org>
Cc: 16963@debbugs.gnu.org
Subject: bug#16963: A patch to create a list-with-tail primitive.
Date: Sat, 29 Mar 2014 09:30:56 -0400	[thread overview]
Message-ID: <1396099856.8469.3.camel@localhost.localdomain> (raw)
In-Reply-To: <53362659.8030106@dancol.org>

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








  reply	other threads:[~2014-03-29 13:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07 13:58 bug#16963: A patch to create a list-with-tail primitive Demetrios Obenour
2014-03-25  2:10 ` Stefan
2014-03-25  2:45   ` Daniel Colascione
2014-03-27 23:37     ` Demetrios Obenour
2014-03-27 23:38       ` Daniel Colascione
2014-03-28  0:43         ` Demetrios Obenour
2014-03-29  1:46         ` Demetrios Obenour
2014-03-29  1:48           ` Daniel Colascione
2014-03-29 13:30             ` Demetrios Obenour [this message]
2016-02-24  2:51 ` Lars Ingebrigtsen
2019-06-26 14:30   ` Lars Ingebrigtsen
2019-06-28  3:14     ` Noam Postavsky
2019-06-28  3:30       ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1396099856.8469.3.camel@localhost.localdomain \
    --to=demetriobenour@gmail.com \
    --cc=16963@debbugs.gnu.org \
    --cc=dancol@dancol.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).