[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Basic questions about elisp
From: |
tomas |
Subject: |
Re: Basic questions about elisp |
Date: |
Thu, 5 Nov 2009 13:57:56 +0100 |
User-agent: |
Mutt/1.5.15+20070412 (2007-04-11) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Nov 05, 2009 at 03:13:32AM -0800, 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:
>
> (dolist (elt lst)
> ;; some codes
> (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
>
> (setq i 0)
> (while (< i (length lst))
> ;; some codes
> (x-nconc lst '(2))))
> (setq i (1+ i)))
>
> 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ás
> And finally, is it the good place to ask such questions about elisp ?
I'd think so, yes
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFK8svUBcgs9XrR2kYRAth8AJwN4fyTcKzMZ4kdHKXuuwlmPcJ0RgCggIXe
ZTA5JsD54pM81Ur1HehQw38=
=fNST
-----END PGP SIGNATURE-----
Re: Basic questions about elisp,
tomas <=
Message not available
Re: Basic questions about elisp, Pascal J. Bourguignon, 2009/11/05
- Re: Basic questions about elisp, David Kastrup, 2009/11/05
- Re: Basic questions about elisp, Francis Moreau, 2009/11/06
- Re: Basic questions about elisp, David Kastrup, 2009/11/06
- Re: Basic questions about elisp, Francis Moreau, 2009/11/06
- Re: Basic questions about elisp, Pascal J. Bourguignon, 2009/11/06
- Re: Basic questions about elisp, Francis Moreau, 2009/11/07
- Re: Basic questions about elisp, Pascal J. Bourguignon, 2009/11/07
- Re: Basic questions about elisp, tomas, 2009/11/08