From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: maphash: improve docstring Date: Mon, 28 Mar 2016 17:57:03 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1459202259 24540 80.91.229.3 (28 Mar 2016 21:57:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Mar 2016 21:57:39 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 28 23:57:33 2016 Return-path: Envelope-to: ged-emacs-devel@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 1akfAC-00055Q-Aa for ged-emacs-devel@m.gmane.org; Mon, 28 Mar 2016 23:57:32 +0200 Original-Received: from localhost ([::1]:43111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akfAB-0008Rq-MG for ged-emacs-devel@m.gmane.org; Mon, 28 Mar 2016 17:57:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akf9z-0008RX-3y for emacs-devel@gnu.org; Mon, 28 Mar 2016 17:57:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akf9u-0006Kh-4K for emacs-devel@gnu.org; Mon, 28 Mar 2016 17:57:19 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:49233) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akf9t-0006KQ-Ud for emacs-devel@gnu.org; Mon, 28 Mar 2016 17:57:14 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1akf9q-0004ve-9x for emacs-devel@gnu.org; Mon, 28 Mar 2016 23:57:10 +0200 Original-Received: from 107-179-153-73.cpe.teksavvy.com ([107.179.153.73]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Mar 2016 23:57:10 +0200 Original-Received: from monnier by 107-179-153-73.cpe.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Mar 2016 23:57:10 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 24 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 107-179-153-73.cpe.teksavvy.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cancel-Lock: sha1:Jmj51WSURxQKAGkRoS980WYMsW8= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:202367 Archived-At: > Docstring for `maphash' doesn't give any answer to the following > question: is the callback FUNCTION allowed to access the hash > table in read mode (I guess yes) and write mode? About the > latter I have no idea without studying internal implementation. > E.g., is the following code going to work as a way to filter a > hash table? Yes, you are allowed to modify the table while iterating over it and the resulting behavior should be sane. And it should have the usual desired properties: The set of elements passed to the function is a superset of all the elements that aren't removed during the iteration, and a subset of all the elements that were present at the beginning or added during the loop. IOW if an entry is untouched during the loop, then it will be passed (exactly once) to the function. If an entry is added or removed during the loop, then maybe it will be passed to the function, but maybe not. And if an entry is modified during the loop, then it will be passed to the function (exactly once) and the value passed will be the one that happens to be current when the function is called. Stefan