From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: lee Newsgroups: gmane.emacs.help Subject: iterating over a list while removing elements Date: Wed, 19 Mar 2014 12:39:43 +0100 Organization: my virtual residence Message-ID: <87mwgmwh6o.fsf@yun.yagibdah.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1395229209 31136 80.91.229.3 (19 Mar 2014 11:40:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Mar 2014 11:40:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 19 12:40:18 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WQEr3-0006Wf-6N for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Mar 2014 12:40:17 +0100 Original-Received: from localhost ([::1]:39932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQEr2-0004Q7-Gu for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Mar 2014 07:40:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQEqm-0004ED-Ul for help-gnu-emacs@gnu.org; Wed, 19 Mar 2014 07:40:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQEqe-0004oG-U8 for help-gnu-emacs@gnu.org; Wed, 19 Mar 2014 07:40:00 -0400 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:38749 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQEqe-0004oC-MR for help-gnu-emacs@gnu.org; Wed, 19 Mar 2014 07:39:52 -0400 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WQEqZ-0007o9-4W for help-gnu-emacs@gnu.org; Wed, 19 Mar 2014 12:39:47 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Mail-Followup-To: help-gnu-emacs@gnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 194.42.186.216 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96626 Archived-At: 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.