From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.help Subject: Re: Basic questions about elisp Date: Thu, 5 Nov 2009 13:44:25 +0100 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257425125 10867 80.91.229.12 (5 Nov 2009 12:45:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2009 12:45:25 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Francis Moreau Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 05 13:45:18 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 1N61iG-0002Hy-0E for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 13:45:16 +0100 Original-Received: from localhost ([127.0.0.1]:34106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N61iF-0002sD-JG for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 07:45:15 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N61ht-0002qZ-6g for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:44:53 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N61hn-0002pF-JT for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:44:51 -0500 Original-Received: from [199.232.76.173] (port=38293 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N61hn-0002p6-DO for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:44:47 -0500 Original-Received: from mail-yx0-f191.google.com ([209.85.210.191]:51815) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N61hn-0005Lt-2j for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:44:47 -0500 Original-Received: by yxe29 with SMTP id 29so7741298yxe.14 for ; Thu, 05 Nov 2009 04:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=4s3xePvYoqS7wksbRTH5BYrj0T3a8cCX0BJHU2R/98E=; b=Z1ltWC2vbMxwAJJ7B1v4u/X6N8GgkIn6qDPGfyPx+KEex7xbSFb5ExDXNVrrm9+45s ghhDkqvnCBbwJOKktQ6Bc7RSYi9SYezTqwLSWxg2+XaF96+UXXm4Npfgngf+ujbdVCA4 iBxZwhcKBkQVMhTiumF8epKQ5FfFFomTbejb0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=MHIuMGFUONomL7WmY8NnMQs1gfi+afr/TI+hsPLNIjjTWbchBvaHxTgBwf0GV+oZyo Q5SODZbI+Yob41qnkqqTO/3SB5ttNbnazGYc6n5Np+5B0a4K1hUBO0fZ5exjiBLYI0vX M13JYpDyASObzq31mF7t73AIBhRKK5XJ5T7Bc= Original-Received: by 10.101.179.5 with SMTP id g5mr208897anp.89.1257425085109; Thu, 05 Nov 2009 04:44:45 -0800 (PST) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:69489 Archived-At: On Thu, Nov 5, 2009 at 1:07 PM, Francis Moreau wro= te: > On Nov 5, 12:50=C2=A0pm, Lennart Borgman wrot= e: >> 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: >> >> > =C2=A0(dolist (elt lst) >> > =C2=A0 =C2=A0;; some codes >> > =C2=A0 =C2=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 >> >> > =C2=A0 =C2=A0(setq i 0) >> > =C2=A0 =C2=A0(while (< i (length lst)) >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; some codes >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(x-nconc lst '(2)))) >> > =C2=A0 =C2=A0 =C2=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. Can't you just add the new elements to the end of the list and in each iteration check if there are anything left in the tail to handle?