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

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

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


From: Nicolas Petton
Subject: Re: plists, alists, and hashtables (was: How to iterate over properties in a plist?)
Date: Tue, 4 Aug 2015 10:29:04 +0000


On Tue Aug 4 11:15:27 2015 GMT+0100, Ted Zlatanov wrote:
> On Sat, 01 Aug 2015 18:49:38 -0400 Stefan Monnier <monnier@iro.umontreal.ca> 
> 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?

The new map.el library provides a common interface for both hashtables and 
alists (as well as other key/value data structures).  Maybe that will make it 
easier for people to use hashtables? 

Cheers,
Nico

reply via email to

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