From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Francis Moreau Newsgroups: gmane.emacs.help Subject: Re: Basic questions about elisp Date: Fri, 6 Nov 2009 08:03:36 -0800 (PST) Organization: http://groups.google.com Message-ID: <4d5245de-4a71-4be7-a445-6d033be48490@g23g2000yqh.googlegroups.com> References: <1e9f8449-09ec-4a84-a332-9f05fadb8aa3@z41g2000yqz.googlegroups.com> <87iqdpdog1.fsf@galatea.local> <871vkdm2p1.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257525651 29174 80.91.229.12 (6 Nov 2009 16:40:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Nov 2009 16:40:51 +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 Nov 06 17:40:44 2009 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 1N6Rrb-0006Kz-O1 for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2009 17:40:40 +0100 Original-Received: from localhost ([127.0.0.1]:48919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N6Rrb-00040M-By for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Nov 2009 11:40:39 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!g23g2000yqh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 53 Original-NNTP-Posting-Host: 213.41.232.205 Original-X-Trace: posting.google.com 1257523417 28488 127.0.0.1 (6 Nov 2009 16:03:37 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 6 Nov 2009 16:03:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g23g2000yqh.googlegroups.com; posting-host=213.41.232.205; posting-account=ekTE0goAAADiVCThPmo4ph0C5bTUhQOx User-Agent: G2/1.0 X-HTTP-Via: 1.1 grimoire.wyplay.int:3128 (squid/2.5.STABLE14) X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061118 Fedora/3.0.11-1.fc9 Firefox/3.0.11, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:174474 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:69551 Archived-At: On 5 nov, 16:06, David Kastrup wrote: > p...@informatimago.com (Pascal J. Bourguignon) writes: > > > > > Francis Moreau writes: > > >> Hello, > > >> I'm trying to learn elisp and have a couple of basic questions. > > >> I'm iterating over a list using dotimes, but in the body of dotimes, > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dol= ist =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dolist > > >> the list can mutate. For example I have: > > >> =A0 (dolist (elt lst) > >> =A0 =A0 ;; some codes > >> =A0 =A0 (nconc lst '(2))) > > > This is an infinite loop. =A0It will break when the program runs out of > > memory. > > It was oversimplified. =A0But it violates one basic principle of > programming: Basic principle of _elisp_ programming, I asssume... > > Only ever use destructive list operators like nconc on lists that have > been consed together _entirely_ under your control. > > In this particular case, the cons '(2) has been consed together under > control of the Lisp reader. =A0The second time this code gets executed, > the cons is destroyed. eh ? When I wrote '(2), I suppose the elisp interpreter to create a new list. And doing (nconc lst '(2)), I assume that this new list is now referenced by 'lst', hence can't be destroyed. I initialy thought that this didn't work, but after retrying it, I got the correct result: (let ((lst (list 1 2 3))) (dolist (elt lst) (when (eq elt 1) (nconc lst '(4)))) lst) which evalutes to "(1 2 3 4)"