[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding many elements to a list
From: |
Pascal J. Bourguignon |
Subject: |
Re: Adding many elements to a list |
Date: |
Tue, 22 Sep 2009 13:53:57 +0200 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) |
David Kastrup <dak@gnu.org> writes:
> pjb@anevia.com (Pascal J. Bourguignon) writes:
>
>> David Kastrup <dak@gnu.org> writes:
>>
>>> pjb@anevia.com (Pascal J. Bourguignon) writes:
>>>
>>>> David Kastrup <dak@gnu.org> writes:
>>>>
>>>>> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>>>>>
>>>>>> So better use (require 'cl) (push new-item list)
>>>>>> or (cons new-item list)
>>>>>> or (append (list new-items...) list)
>>>>>
>>>>> (require 'cl) is quite unnecessary for all of the mentioned
>>>>> alternatives.
>>>>
>>>> Not on emacs version < 23.
>>>
>>> Nonsense. push&pop were officially announced in Emacs 21.1. I may be
>>> mistaken, but I think they have been there even earlier.
>>>
>>> And the other options certainly were there from the earliest versions of
>>> GNU Emacs.
>>
>> C-h f push RET
>> push is a Lisp macro in `cl.el'.
>> (push x place)
>>
>> Insert x at the head of the list stored in place.
>> Analogous to (setf place (cons x place)), though more careful about
>> evaluating each argument only once and in the right order. place may
>> be a symbol, or any generalized variable allowed by `setf'.
>>
>> [back]
>>
>> M-x emacs-version RET
>> GNU Emacs 22.2.1 (x86_64-unknown-linux-gnu, X toolkit) of 2008-08-21 on
>> simias
>
> Try emacs -Q. Just because you choose to load some library overloading
> the default operators does not mean that other people should do the same
> when Emacs will provide those operators by default, with better
> performance.
Ah! :-)
The cl package wouldn't be provided if the default had any performance at all...
(defvar *a* (cons nil nil))
(push 1 (car *a*))
Debugger entered--Lisp error: (wrong-type-argument symbolp (car *a*))
(setq (car *a*) (cons 1 (car *a*)))
(push 1 (car *a*))
eval((push 1 (car *a*)))
eval-last-sexp-1((4))
eval-last-sexp((4))
call-interactively(eval-last-sexp)
(require 'cl)
(push 1 (car *a*))
--> (1)
*a*
--> ((1))
--
__Pascal Bourguignon__
- Adding many elements to a list, Nordlöw, 2009/09/18
- Re: Adding many elements to a list, Pascal J. Bourguignon, 2009/09/18
- Re: Adding many elements to a list, David Kastrup, 2009/09/18
- Re: Adding many elements to a list, Pascal J. Bourguignon, 2009/09/19
- Re: Adding many elements to a list, David Kastrup, 2009/09/18
- Re: Adding many elements to a list, Thierry Volpiatto, 2009/09/18
- Re: Adding many elements to a list, Pascal J. Bourguignon, 2009/09/19
- Re: Adding many elements to a list, Andreas Politz, 2009/09/19
- Re: Adding many elements to a list, David Kastrup, 2009/09/22
- Re: Adding many elements to a list,
Pascal J. Bourguignon <=
- Re: Adding many elements to a list, David Kastrup, 2009/09/22
- Re: Adding many elements to a list, Pascal J. Bourguignon, 2009/09/22
- Re: Adding many elements to a list, David Kastrup, 2009/09/22
- Re: Adding many elements to a list, Samuel Wales, 2009/09/28
Re: Adding many elements to a list, David Kastrup, 2009/09/18