unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* iterating over a list while removing elements
@ 2014-03-19 11:39 lee
  2014-03-19 12:39 ` Stefan
  2014-03-19 13:11 ` Michael Albinus
  0 siblings, 2 replies; 11+ messages in thread
From: lee @ 2014-03-19 11:39 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

what is the defined behaviour when you iterate over a list and remove
elements from that very list?  For example:


(defsubst multisearch-directory-ref-p (dots)
  "Return t when the string DOTS ends in a directory reference."
  (or
   (string-match "\\.$" dots)
   (string-match "\\.\\.$" dots)))

(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)))
    (dolist (entry files-list files-list)
      (unless (and
	       (not (multisearch-directory-ref-p entry))
	       (file-directory-p entry)
	       (file-readable-p entry))
	(setq files-list (delete entry files-list))))))


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


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



^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <mailman.17526.1395229207.10748.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2014-03-21  5:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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