From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.devel Subject: Re: RFC: make maphash return a list Date: Sat, 04 May 2013 01:12:58 +0200 Organization: Informatimago Message-ID: <87txmjwtc5.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1367622770 23741 80.91.229.3 (3 May 2013 23:12:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 3 May 2013 23:12:50 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 04 01:12:48 2013 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 1UYP9j-00042P-E6 for ged-emacs-devel@m.gmane.org; Sat, 04 May 2013 01:12:47 +0200 Original-Received: from localhost ([::1]:36827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYP9i-0003af-W6 for ged-emacs-devel@m.gmane.org; Fri, 03 May 2013 19:12:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYP9f-0003aa-LC for emacs-devel@gnu.org; Fri, 03 May 2013 19:12:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYP9e-0000Cd-6l for emacs-devel@gnu.org; Fri, 03 May 2013 19:12:43 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:39199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYP9e-0000CT-0I for emacs-devel@gnu.org; Fri, 03 May 2013 19:12:42 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UYP9b-0003vT-8z for emacs-devel@gnu.org; Sat, 04 May 2013 01:12:39 +0200 Original-Received: from amontsouris-651-1-14-160.w90-46.abo.wanadoo.fr ([90.46.105.160]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 04 May 2013 01:12:39 +0200 Original-Received: from pjb by amontsouris-651-1-14-160.w90-46.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 04 May 2013 01:12:39 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-651-1-14-160.w90-46.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:MTUwNWVmNDRlYTg2ODUyMjEwMDU4YjQ4MzExNWVjZDA5N2FlYjk1OA== 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:159280 Archived-At: Wilfred Hughes writes: > I've been using Emacs hash tables a lot recently, and I would find > several operations much easier if maphash returned a list. For > example, I'd like to be able to do: > > (maphash (lambda (key value) key) some-table) > > to obtain the list of keys present in some-table. I would guess elisp > is influenced by Common Lisp here, where maphash returns nil > unconditionally. However, unlike elisp, Common Lisp's loop macro > supports iterating over keys directly with (loop for key being > hash-key of some-table ...) which helps considerably. > > I can't see any obvious way this would break backwards compatibility, > so I threw together a trivial patch that makes maphash return a list > of the results. I've attached the patch. > > Is there interest in this? maphash is nice because it doesn't cons a list. (setq lexical-binding t) (defun hashmap (fun hash) "Returns a list of the results of fun called on each key value entry. No defined order." (let ((result '())) (maphash (lambda (k v) (push (funcall fun k v) result)) hash) result)) (let ((h (make-hash-table))) (setf (gethash :u h) 1 (gethash :d h) 2 (gethash :t h) 3 (gethash :q h) 4 (gethash :c h) 5 (gethash :s h) 6) (hashmap (function cons) h)) --> ((:s . 6) (:c . 5) (:q . 4) (:t . 3) (:d . 2) (:u . 1)) -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.