From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Add-to-list or setq append... Date: Wed, 04 Aug 2010 18:12:04 +1000 Organization: Unlimited download news at news.astraweb.com Message-ID: <871vaebxuz.fsf@puma.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291853837 20966 80.91.229.12 (9 Dec 2010 00:17:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 00:17:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 01:17:13 2010 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.69) (envelope-from ) id 1PQUC8-000829-OF for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 01:17:12 +0100 Original-Received: from localhost ([127.0.0.1]:46680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQUC7-0001O3-P6 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 19:17:12 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news-xfer.nntp.sonic.net!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:H53iPLtX3mFqixygAxzquXJWdhw= Original-Lines: 43 Original-NNTP-Posting-Host: 28035ec4.news.astraweb.com Original-X-Trace: DXC=M8[H[:_e>ekF1iA^=`ZUjbL?0kYOcDh@jW\:Hm@YlDbjR8J33anb9@o\6:o3aKBMRm0Tg^6]fWoeb Original-Xref: usenet.stanford.edu gnu.emacs.help:180341 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:76281 Archived-At: Andrea Crotti writes: > Just a curiosity, I was wondering why in so many README and doc they > suggest to add elements to lists with something like: > > (setq list (append list element)) > > instead of doing simply > (add-to-list list-va element) > > Is there any good reason or is just historical heritage? > I think add-to-list is even more smart adding only if not there already, > then what's the point in using that ugly form? > Possibly a bit of both. Both forms have their use. Some will likely argue that setq is more general and can be used to add items at the end via append or at the beginning using cons etc. However, they a probably not aware that add-to-list, by default adds the element at the beginning of the list, but has an optional argument to add it at the end. some will argue that add-to-list only does an 'equal' test to determine if the element is already in the list, but this too can be changed with an optional argument. One area where add-to-list is weak is when you want to add the element to a specific location that is not at the start or end of the list. The other point to note is that add-to-list modifies its list argument i.e. is destructive. (append l v) creates a new list and does not modify l, which is why you need the setq. Frequently, you see append, cons etc because it is more 'lispish'. Back when many places used lisp and scheme to teach, many new emacs users came to elisp having already learnt a lisp. For them, append, cons, push etc were/are more familiar idioms while add-to-list is more dialect specific. Tim -- tcross (at) rapttech dot com dot au