help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

plists, alists, and hashtables (was: How to iterate over properties in a


From: Ted Zlatanov
Subject: plists, alists, and hashtables (was: How to iterate over properties in a plist?)
Date: Tue, 04 Aug 2015 06:15:27 -0400
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

On Sat, 01 Aug 2015 18:49:38 -0400 Stefan Monnier <address@hidden> wrote: 

SM> - plists need to be "parsed" in order to figure out if an element is a key
SM>   or a value.

That's true, but there's some idea that a plist is "correct" if it can
be parsed. It's also visually easier to parse, I think, especially for
beginners. Also, symbol plists are pretty well ensconced at the C level.

By contrast, alists don't have a strong structure and parsing them is
not simple for beginners. For instance:

(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
(alist-get 'd '((a) (b 1) (c . 2) d)) -> nil ; no error

The real map type in Emacs Lisp is the hashtable, I think. But because
of historical baggage, we end up discussing the benefits of two list
formats when used as maps. Which feels like discussing which of two
different bicycles is better for carrying 5 people.

For instance, the hashtable keys are unambiguously
(hash-table-keys my-hashtable) and there's no looping or parsing.

I wonder, if hashtables had a better reader syntax (like plists or
alists) and better Customize support, would they see wider use? Or is
the historical baggage in tutorials and existing code too much at this
point?

Ted


reply via email to

[Prev in Thread] Current Thread [Next in Thread]