[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: plists, alists, and hashtables
From: |
Stefan Monnier |
Subject: |
Re: plists, alists, and hashtables |
Date: |
Thu, 06 Aug 2015 15:12:54 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
> (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
- Re: plists, alists, and hashtables, (continued)
- Re: plists, alists, and hashtables, Barry Margolin, 2015/08/05
- Re: plists, alists, and hashtables, Robert Thorpe, 2015/08/05
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/05
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/06
- RE: plists, alists, and hashtables, Drew Adams, 2015/08/06
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/06
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/06
- RE: plists, alists, and hashtables, Drew Adams, 2015/08/05
Re: plists, alists, and hashtables,
Stefan Monnier <=
Message not available
Message not available
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/06
- Re: plists, alists, and hashtables, Ted Zlatanov, 2015/08/06
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/07
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/07
- Message not available
- Re: plists, alists, and hashtables, Pascal J. Bourguignon, 2015/08/07
- Re: plists, alists, and hashtables, Stefan Monnier, 2015/08/08