unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: lee <lee@yun.yagibdah.de>
To: help-gnu-emacs@gnu.org
Subject: Re: iterating over a list while removing elements
Date: Thu, 20 Mar 2014 17:02:26 +0100	[thread overview]
Message-ID: <87bnx0x3hp.fsf@yun.yagibdah.de> (raw)
In-Reply-To: <jwvha6u1ibe.fsf-monnier+gmane.emacs.help@gnu.org> (Stefan's message of "Wed, 19 Mar 2014 08:39:39 -0400")

Stefan <monnier@iro.umontreal.ca> 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
https://github.com/lee-/emacs/tree/master/multisearch


-- 
Knowledge is volatile and fluid.  Software is power.



  reply	other threads:[~2014-03-20 16:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19 11:39 iterating over a list while removing elements lee
2014-03-19 12:39 ` Stefan
2014-03-20 16:02   ` lee [this message]
2014-03-19 13:11 ` Michael Albinus
2014-03-20 16:10   ` lee
     [not found] <mailman.17526.1395229207.10748.help-gnu-emacs@gnu.org>
2014-03-19 13:12 ` Pascal J. Bourguignon
2014-03-19 18:28   ` Joost Kremers
2014-03-20 17:34     ` lee
2014-03-20 20:16       ` Eli Zaretskii
2014-03-21  5:25         ` lee
2014-03-20 16:33   ` lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnx0x3hp.fsf@yun.yagibdah.de \
    --to=lee@yun.yagibdah.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).