[Top][All Lists]

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

Re: iterating over a list while removing elements

From: lee
Subject: Re: iterating over a list while removing elements
Date: Thu, 20 Mar 2014 17:02:26 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Stefan <address@hidden> writes:

>>    (string-match "\\.$" dots)
>>    (string-match "\\.\\.$" dots)))
> You meant
>     (string-match "\\.\\'" dots)
>     (string-match "\\.\\.\\'" dots)))

Hm, what`s the difference?

>> Surprisingly, this /appears/ to work.  Can I take that for granted, or
>> is this a stupid thing to do?  It`s like someone pulling the chair
>> you`re about to sit on from underneath you ...
> This is undocumented, so better not rely on the details of the behavior.
> You can rely on the fact that dolist will behave sanely, tho: it should
> not go berzerk, it should go through at least all elements still
> remaining in the list, and at most all elements that have been in
> the list.
> But you should better not assume that dolist will skip the "entry" you
> just removed.  E.g. you could do the following, which should be somewhat
> faster (since `delete' is O(n)):

Duplicating the list is an approach I used at other places, and I was
wondering if there`s some way to do it without duplication.  The list
can be fairly large, and I`m using several, so saving some memory would
be nice, even if it usually doesn`t really matter.

Anyway, redundancy through `delete' isn`t good, letting aside that it
may yield unexpected results.

> (defun multisearch-make-files-list (directory)
>   "Return a list of files in DIRECTORY, with directory references
> and directories removed."
>   (let ((files-list (directory-files directory t))
>         (newlist '()))

Why not (newlist nil)?

I`ve got it working nicely now, you can find the whole thing at

Knowledge is volatile and fluid.  Software is power.

reply via email to

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