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: Barry Margolin
Subject: Re: Basic questions about elisp
Date: Fri, 06 Nov 2009 00:06:16 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article <address@hidden>,
 address@hidden (Pascal J. Bourguignon) wrote:

> Francis Moreau <address@hidden> 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.

It also modifies a literal, which modifies the function itself 
(resulting in a circular list of (2 2 2 2 ...)).  Change that nconc to:

(nconc lst (list 2))

to avoid that.

> 
> 
> > 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.

-- 
Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


reply via email to

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