From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Wanted: Adding list-elements into an existing list Date: Fri, 17 Oct 2008 00:32:02 +0200 Organization: Informatimago Message-ID: <87wsg8w4rh.fsf@hubble.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1224196849 9093 80.91.229.12 (16 Oct 2008 22:40:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Oct 2008 22:40:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 17 00:41:48 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KqbXP-0003Lf-FG for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Oct 2008 00:41:47 +0200 Original-Received: from localhost ([127.0.0.1]:56024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KqbWK-0003Nq-Mx for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Oct 2008 18:40:40 -0400 Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:hvKv+OraQoaMaLXylCa2OPu7TDY= Original-Lines: 55 Original-NNTP-Posting-Date: 17 Oct 2008 00:32:02 MEST Original-NNTP-Posting-Host: 88.182.134.169 Original-X-Trace: 1224196322 news-2.free.fr 14076 88.182.134.169:46114 Original-X-Complaints-To: abuse@proxad.net Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!oleane.net!oleane!feed.ac-versailles.fr!proxad.net!feeder1-2.proxad.net!cleanfeed2-a.proxad.net!nnrp13-1.free.fr!not-for-mail Original-Xref: news.stanford.edu gnu.emacs.help:163513 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58856 Archived-At: Nordlöw writes: > Is there a variant of the function add-to-list(a b) where b can be a > list aswell? With add-to-list, the second argument can be anything you want. (defvar my-list nil) (add-to-list 'my-list '(a b c)) (add-to-list 'my-list '(1 2 3)) (add-to-list 'my-list '(a b c)) my-list --> ((1 2 3) (a b c)) > (add-list-elements-to-list '(a b c) '(c d e)) should evaluate '(a b c > d e) What about: (defun add-to-list-several-elements (list-variable elements &optional append compare-fn) (dolist (element elements) (add-to-list list-variable element append compare-fn)) (symbol-value list-variable)) (add-to-list-several-elements 'my-list '((1 2 3) (3 2 1))) --> ((3 2 1) (1 2 3) (a b c)) > or do I have to implement it myself using an iteration-construct? Yes. However, add-to-list is not an example to follow. It is not a function, since it works by side effect. It would be better to work with pure functions such as union. (let ((my-list (list '(1 2 3) '(a b c)))) (let ((augmented-list (union my-list (list '(1 2 3) '(3 2 1)) :test (function equal)))) augmented-list)) --> ((3 2 1) (1 2 3) (a b c)) -- __Pascal Bourguignon__ http://www.informatimago.com/ Nobody can fix the economy. Nobody can be trusted with their finger on the button. Nobody's perfect. VOTE FOR NOBODY.