From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.help Subject: Re: Basic questions about elisp Date: Thu, 05 Nov 2009 16:06:02 +0100 Organization: Organization?!? Message-ID: <871vkdm2p1.fsf@lola.goethe.zz> References: <1e9f8449-09ec-4a84-a332-9f05fadb8aa3@z41g2000yqz.googlegroups.com> <87iqdpdog1.fsf@galatea.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1257436038 19872 80.91.229.12 (5 Nov 2009 15:47:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2009 15:47:18 +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 Nov 05 16:47:12 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 1N64YI-0006JS-RA for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 16:47:11 +0100 Original-Received: from localhost ([127.0.0.1]:39583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N64YI-0004zH-E2 for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 10:47:10 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!kanaga.switch.ch!switch.ch!news.belwue.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:J2bG7YU5tb7PF1r7xH4Ceg07SBY= Original-Lines: 40 Original-NNTP-Posting-Date: 05 Nov 2009 16:06:07 CET Original-NNTP-Posting-Host: 7c8445ff.newsspool1.arcor-online.net Original-X-Trace: DXC=1I; ]_3SRNoeeoCI^f\Y]Eaic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbReN@5C?O<\n1_LiI6ENVam3>5MOK` 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:69500 Archived-At: pjb@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, > dolist dolist > >> the list can mutate. For example I have: >> >> (dolist (elt lst) >> ;; some codes >> (nconc lst '(2))) > > This is an infinite loop. It will break when the program runs out of > memory. It was oversimplified. But it violates one basic principle of programming: 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. The second time this code gets executed, the cons is destroyed. For example, the code (let ((lst (list 1 2 3))) (dotimes (i 2 lst) (nconc lst '(2)))) never finishes. After 2 iterations, you get a circular list which hangs the third nconc. -- David Kastrup