From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: Basic questions about elisp Date: Thu, 5 Nov 2009 13:57:56 +0100 Message-ID: <20091105125756.GB12911@tomas> 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; x-action=pgp-signed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257425666 12616 80.91.229.12 (5 Nov 2009 12:54:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2009 12:54:26 +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:54:19 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 1N61r1-0006SF-IT for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 13:54:19 +0100 Original-Received: from localhost ([127.0.0.1]:45517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N61r0-0005lY-Vf for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 07:54:18 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N61qe-0005kW-LT for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:53:56 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N61qa-0005k4-1Z for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:53:56 -0500 Original-Received: from [199.232.76.173] (port=50858 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N61qZ-0005k1-UY for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:53:51 -0500 Original-Received: from alextrapp1.equinoxe.de ([217.22.192.104]:58686 helo=www.elogos.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N61qZ-0006ZM-I1 for help-gnu-emacs@gnu.org; Thu, 05 Nov 2009 07:53:51 -0500 Original-Received: by www.elogos.de (Postfix, from userid 1000) id D02DF90008; Thu, 5 Nov 2009 13:57:56 +0100 (CET) Content-Disposition: inline In-Reply-To: <1e9f8449-09ec-4a84-a332-9f05fadb8aa3@z41g2000yqz.googlegroups.com> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) 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:69490 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Nov 05, 2009 at 03:13:32AM -0800, Francis Moreau wrote: > Hello, >=20 > I'm trying to learn elisp and have a couple of basic questions. >=20 > I'm iterating over a list using dotimes, but in the body of dotimes, > the list can mutate. For example I have: >=20 > (dolist (elt lst) > ;; some codes > (nconc lst '(2))) >=20 > This adds/appends a new element to 'lst' list. It looks like 'dotimes' > doesn't like it. >=20 > So I eventually wrote it like this >=20 > (setq i 0) > (while (< i (length lst)) > ;; some codes > (x-nconc lst '(2)))) > (setq i (1+ i))) >=20 > which is a bit ugly, is there another way to do that ? What about: (let ((l lst)) (while l (do-something-with (car l)) (setq l (cdr l)))) This should be fine as long as you only append to lst. Dragons might emerge whenever you do more drastic things to it ;-) (and you would have to re-think things when Emacs Lisp becomes multi-threaded. It might work then and it might not). Regards - -- tom=C3=A1s > And finally, is it the good place to ask such questions about elisp ? I'd think so, yes Regards - -- tom=C3=A1s -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFK8svUBcgs9XrR2kYRAth8AJwN4fyTcKzMZ4kdHKXuuwlmPcJ0RgCggIXe ZTA5JsD54pM81Ur1HehQw38=3D =3DfNST -----END PGP SIGNATURE-----