[Top][All Lists]

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

New assoc-let package

From: Artur Malabarba
Subject: New assoc-let package
Date: Wed, 3 Dec 2014 23:40:14 +0000

Hi All,

As part of another project, which involves excessive handing of
alists, I wrote up a little macro which has turned out to be
stupendously useful. I'm just checking whether this functionality is
already offered somewhere, because if it isn't I'll make an Elpa
package for it.

Simply put, the macro takes an alist and a body, and makes the data of
the alist accessible by just writing the car of the desired cell
preceded by a dot.
For instance, the following:

  (assoc-let alist
    (if (and .title .body)

expands to

  (let ((.title (cdr (assoc 'title alist)))
        (.body (cdr (assoc 'body alist)))
        (.site (cdr (assoc 'site alist))))
    (if (and .title .body)

Obviously, this only works for alist elements whose car are symbols,
and it shadows outside variables whose names start with a dot (which
I've never ever run into). Still, this has proven invaluable for
processing the output of `json-read'.


reply via email to

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