New on Elpa and in Emacs 25.1: let-alist15 Dec 2014, by Artur Malabarba.
New in 25.1 post series
- New in Emacs 25.1: Query-replace history is enhanced.
- New in Emacs 25.1: Better Rectangles
- New on Elpa and in Emacs 25.1: let-alist
- New in Emacs 25.1: Easily install multifile package from a directory
- New in Emacs 25.1: comment-line
- New on Elpa and in Emacs 25.1: seq.el
- New in Emacs 25.1: Have prettify-symbols-mode reveal the symbol at point
- New in Emacs 25.1: Round quotes in Help buffers
- New in Emacs 25.1: Easily search for non-ASCII characters
- New in Emacs 25.1: EWW improvements
- New in Emacs 25.1: map.el library
- New in Emacs 25.1: More flow control macros
let-alist is the best thing to happen to associative lists since the
invention of the cons cell. This little macro lets you easily access the
contents of an alist, concisely and efficiently, without having to specify them
preemptively. It comes built-in with 25.1, and is also available on GNU Elpa for
If you've ever had to process the output of a web API, you've certainly had to
deal with endless alists returned by
json-read. I'll spare you the rant and go
straight to the example.
Here's a very simplified version of a function of the SX package, before
And this is what the same function looks like now (again, simplified).
How much nicer is that?
let-alist detects all those symbols that start with a
., and wraps the body in a
let form essentially identical to the one above.
The resulting code is much nicer to write, and the byte-compiled result is
exactly as efficient as the manually written version. (If it's not
byte-compiled, there will be a performance difference, though it should be
And just to make things nicer, you can use this snippet to highlight those
symbols as if they were keywords.
Due to popular demand,
let-alist now does nested alists. The example above
shows how you can use
.owner.display_name to access the value of
display_name inside the value of