[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
iterating over a list while removing elements
From: |
lee |
Subject: |
iterating over a list while removing elements |
Date: |
Wed, 19 Mar 2014 12:39:43 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
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.