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: Thu, 5 Nov 2009 04:07:11 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <1e9f8449-09ec-4a84-a332-9f05fadb8aa3@z41g2000yqz.googlegroups.com> 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 1257424865 10093 80.91.229.12 (5 Nov 2009 12:41:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2009 12:41:05 +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 13:40:58 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 1N61dy-0000D5-PC for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 13:40:51 +0100 Original-Received: from localhost ([127.0.0.1]:52404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N61dy-0000Hd-2v for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 07:40:50 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!r5g2000yqb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-NNTP-Posting-Host: 93.2.234.186 Original-X-Trace: posting.google.com 1257422831 32458 127.0.0.1 (5 Nov 2009 12:07:11 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 5 Nov 2009 12:07:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r5g2000yqb.googlegroups.com; posting-host=93.2.234.186; 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:174412 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:69488 Archived-At: On Nov 5, 12:50=A0pm, Lennart Borgman wrote: > On Thu, Nov 5, 2009 at 12:13 PM, Francis Moreau = wrote: > > 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, > > the list can mutate. For example I have: > > > =A0(dolist (elt lst) > > =A0 =A0;; some codes > > =A0 =A0(nconc lst '(2))) > > > This adds/appends a new element to 'lst' list. It looks like 'dotimes' > > doesn't like it. > > > So I eventually wrote it like this > > > =A0 =A0(setq i 0) > > =A0 =A0(while (< i (length lst)) > > =A0 =A0 =A0 =A0 =A0;; some codes > > =A0 =A0 =A0 =A0 =A0(x-nconc lst '(2)))) > > =A0 =A0 =A0(setq i (1+ i))) > > > which is a bit ugly, is there another way to do that ? > > It is much easier to answer if you define exactly what you want to do > when lst grows. I'd like to iterate over all elements of the list even if the element are appended during the loop execution. For example if the list is (1 2) before entering in the loop and then during the first iteration the code append '3' to the list so it becomes (1 2 3), I'd like the loop to iterate over the '3' element as well. 'dotimes' doesn't seem to do that. I noticed that I used 'x-nconc' without giving its definition: it is something I wrote for my own need: it's the same as 'nconc' except if the list given in parameter is nil then 'x-nconc' creates a new list and assigns it to its first parameter. I did the following macro to do that, although I'm not sure it's the good thing to do: (defmacro x-nconc (l e) `(if (null ,l) (setq ,l ,e) (nconc ,l ,e))) Thanks