help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic questions about elisp


From: Pascal J. Bourguignon
Subject: Re: Basic questions about elisp
Date: Thu, 05 Nov 2009 15:41:02 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Francis Moreau <francis.moro@gmail.com> 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.


> This adds/appends a new element to 'lst' list. It looks like 'dotimes'
                                                                dolist
> doesn't like it.

If you are not careful, you won't be able to program...


> I also need to iterate over elements of a vector.  I basically use a
> 'while' loop as above. Is there any helper to do that, I looked at
> "(elisp) Sequences Arrays Vectors" but found nothing appropriate.

(require 'cl)
(loop for element in list       do (something element))
(loop for element across vector do (something element))


> And finally, is it the good place to ask such questions about elisp ?

Yes, it's right here.

-- 
__Pascal Bourguignon__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]