John Kitchin has a short video in his Scimax channel that considers another Elisp construct. This video talks about let and its siblings. One of the first non-trivial things a new Lisper learns is how to deal with local variables using let
.
If that didn’t make sense to you, Kitchin’s video explains it all. If you’re familiar with any of the Lisp dialects, you’ll also be familiar with let
. It turns out, though, that there’s still a bit to learn. Elisp has additional let constructs that are reminiscent of Common Lisp’s destructuring-bind.
The first, let-alist, binds each car
of an alist
to its corresponding cdr
. If you have to deal with several entries in an alist
, it’s a way of referring to an alist
value by name instead of the normal assoc/car/cdr
dance.
The second, seq-let, is similar except that it takes two lists. The first is a list of symbols that are bound to the corresponding items in the second list. This is basically a scaled down version destructuring-bind
.
Finally, Kitchin mentions pcase-let, which binds patterns to values. It’s much more complex than the others so Kitchin doesn’t discuss it in depth.
This is a short video, 12 minutes, 12 seconds, but it’s really useful for Elisp n00bs and those not familiar with let-alist
, seq-alist
, and pcase-let
. If you fall into either category, be sure to take a look.