From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: plists, alists, and hashtables Date: Thu, 06 Aug 2015 15:12:54 -0400 Message-ID: References: <876150vwaa.fsf@mbork.pl> <873803x5q4.fsf@kuiper.lan.informatimago.com> <87a8u7we9s.fsf_-_@lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1438888418 5736 80.91.229.3 (6 Aug 2015 19:13:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Aug 2015 19:13:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 06 21:13:30 2015 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 1ZNQbZ-0005KM-Gt for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Aug 2015 21:13:29 +0200 Original-Received: from localhost ([::1]:46267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNQbY-0002az-Gq for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Aug 2015 15:13:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNQbH-0002YG-85 for help-gnu-emacs@gnu.org; Thu, 06 Aug 2015 15:13:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNQbC-0006km-UU for help-gnu-emacs@gnu.org; Thu, 06 Aug 2015 15:13:11 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:50460) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNQbC-0006jL-Nk for help-gnu-emacs@gnu.org; Thu, 06 Aug 2015 15:13:06 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZNQb9-00051M-EU for help-gnu-emacs@gnu.org; Thu, 06 Aug 2015 21:13:03 +0200 Original-Received: from 157-52-5-248.cpe.teksavvy.com ([157.52.5.248]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 06 Aug 2015 21:13:03 +0200 Original-Received: from monnier by 157-52-5-248.cpe.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 06 Aug 2015 21:13:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 54 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 157-52-5-248.cpe.teksavvy.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:MmI8LCzEa8i3Gx5jMIwgz83RjjE= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:106295 Archived-At: > (alist-get 'a '((a) (b 1) (c . 2) d)) -> nil > (alist-get 'b '((a) (b 1) (c . 2) d)) -> (1) > (alist-get 'c '((a) (b 1) (c . 2) d)) -> 2 These are all consistent since your list is really ((a . nil) (b . (1)) (c . 2) d) > (alist-get 'd '((a) (b 1) (c . 2) d)) -> nil ; no error Just like Javascript, Elisp often errs on "don't signal an error" when it bumps into something that's of the wrong type. I don't like it very much, but it has its advantages as well. > The real map type in Emacs Lisp is the hashtable, I think. I think that's a bias you get from other languages. > For instance, the hashtable keys are unambiguously > (hash-table-keys my-hashtable) and there's no looping or parsing. For instance, the alist's keys are unambiguously (mapcar #'car my-alist) and there's no looping or parsing. Also known as: For instance, the plist's keys are unambiguously (plist-keys my-plist) and there's no looping or parsing. [ And no, please don't go and add plist-keys to subr-x.el. ] > However after perl and python (and awk) and... almost any language invented > in the last 20 years, its rather backward. > The efficiency is one thing The efficiency argument is far from clear, since the cut-off point is not too far from 100 last time I checked (IOW alist-get is faster than gethash for tables of less than a hundred elements). That was a while ago, so it may be worth re-benchmarking it. Also, I'd welcome patches which optimize hash-tables for smaller sizes. In any case, other than a vague complaint about Elisp being different from your favorite language, I don't know precisely how to interpret this thread. More specifically, I highly doubt that a special «k1 v1 k2 v2 ...» syntax for hash-tables would make much difference compared to (hash-table k1 v1 k2 v2 ...) which you can get today with a very simple `hash-table' macro. I mean, you'd still have to say (gethash k m), whereas you'd probably want something like m.k, etc... For better or for worse, Elisp is not Python. Stefan