[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mutate list by appending a list (and similar for props)
From: |
Pascal J. Bourguignon |
Subject: |
Re: mutate list by appending a list (and similar for props) |
Date: |
Thu, 18 Sep 2014 18:53:49 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Sam Halliday <sam.halliday@gmail.com> writes:
>
>> > (setq list (append additional-list list))
>>
>> Thanks! But that's not ideal because it involves repeating the list
>> symbol (which can often be quite long).
>
> Try (cl-callf2 append additional-list list) instead, which expands
> exactly into the above expression.
No!
You want prependf:
(require 'cl) ; of course!
(define-modify-macro appendf (&rest args) append "Append onto list")
(let ((list '(1 2 3)))
(appendf list '(4 5 6) '(7 8 9))
list)
--> (1 2 3 4 5 6 7 8 9)
(defun prepend (dest-list &rest other-lists)
(apply (function append) (append other-lists (list dest-list))))
(define-modify-macro prependf (&rest args) prepend "Prepend to list")
(let ((list '(1 2 3)))
(prependf list '(4 5 6) '(7 8 9))
list)
--> (4 5 6 7 8 9 1 2 3)
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk