If you like the simplicity and regularity that libraries such as s for strings and dash for lists provide, you should take a look at Wilfred Hughes’ ht library for working with hash tables.
Hash tables are, of course, built-in to Emacs Lisp so the library isn’t introducing any new functionality but it does offer these advantages as listed in the README
:
- A consistent naming scheme
- If you aren’t using hash tables all the time, it’s hard to remember the function names because they seem entirely unrelated to each other. In the ht library, the names all have the form
ht-X
, whenX
is usually a verb (such ascreate
) that describes what the function does - A natural and consistent argument ordering
- Again, this makes it easier to remember how to use the functions. Of course, eldoc can help here too.
- The mutation functions return
nil
- As in Scheme, these functions end in
!
. Examples areht-set!
to add a key/value pair to the hash table andht-remove!
to remove a key/value pair. - A more comprehensive set of functions for hash table operations
- These make common operations more convenient by providing a function for them so you don’t have to write additional code
The library looks pretty nice if you don’t mind using non-standard names for the operations. Of course, that’s part of the point. The names make more sense and help you remember them. My only complaint with the new names is that the predicates (ht-contains?
, ht-equal?
, …) end with ?
rather than the conventional (for Elisp) -p
. (Yes, yes, I know; The ?
makes more sense but the -p
is a long standing convention worth respecting.)