[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#16963: A patch to create a list-with-tail primitive.
From: |
Demetrios Obenour |
Subject: |
bug#16963: A patch to create a list-with-tail primitive. |
Date: |
Sat, 29 Mar 2014 09:30:56 -0400 |
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
- bug#16963: A patch to create a list-with-tail primitive., Demetrios Obenour, 2014/03/07
- bug#16963: A patch to create a list-with-tail primitive., Stefan, 2014/03/24
- bug#16963: A patch to create a list-with-tail primitive., Daniel Colascione, 2014/03/24
- bug#16963: A patch to create a list-with-tail primitive., Demetrios Obenour, 2014/03/27
- bug#16963: A patch to create a list-with-tail primitive., Daniel Colascione, 2014/03/27
- bug#16963: A patch to create a list-with-tail primitive., Demetrios Obenour, 2014/03/27
- bug#16963: A patch to create a list-with-tail primitive., Demetrios Obenour, 2014/03/28
- bug#16963: A patch to create a list-with-tail primitive., Daniel Colascione, 2014/03/28
- bug#16963: A patch to create a list-with-tail primitive.,
Demetrios Obenour <=