unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* New assoc-let package
@ 2014-12-03 23:40 Artur Malabarba
  2014-12-04  3:54 ` Stefan Monnier
  2014-12-04 19:36 ` Ted Zlatanov
  0 siblings, 2 replies; 35+ messages in thread
From: Artur Malabarba @ 2014-12-03 23:40 UTC (permalink / raw)
  To: emacs-devel

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)
        .body
      .site))

expands to

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


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'.

Cheers
Malabarba



^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2014-12-10 19:14 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-03 23:40 New assoc-let package Artur Malabarba
2014-12-04  3:54 ` Stefan Monnier
2014-12-05  0:36   ` Artur Malabarba
2014-12-05  2:49     ` Leo Liu
2014-12-06  2:27       ` Ted Zlatanov
2014-12-04 19:36 ` Ted Zlatanov
2014-12-05  0:33   ` Artur Malabarba
2014-12-05  0:45     ` Ted Zlatanov
2014-12-05 20:27       ` Artur Malabarba
2014-12-05 20:28         ` Artur Malabarba
2014-12-06 11:36           ` Christopher Schmidt
2014-12-06 19:24             ` Artur Malabarba
2014-12-06 19:58               ` Christopher Schmidt
2014-12-07 16:25                 ` Ted Zlatanov
2014-12-06  2:42         ` Ted Zlatanov
2014-12-06  4:55           ` Stefan Monnier
2014-12-08 10:56             ` Ted Zlatanov
2014-12-08 12:11               ` Artur Malabarba
2014-12-08 14:01                 ` Ted Zlatanov
2014-12-08 15:01                 ` Stefan Monnier
2014-12-08 14:59               ` Stefan Monnier
2014-12-08 15:35                 ` Ted Zlatanov
2014-12-08 15:56                 ` Stefan Monnier
2014-12-08 18:23                 ` Artur Malabarba
2014-12-08 18:28                   ` Artur Malabarba
2014-12-08 20:07                     ` Stefan Monnier
2014-12-09  3:37                       ` Artur Malabarba
2014-12-09 16:57                         ` Stefan Monnier
2014-12-10 15:20             ` Ted Zlatanov
2014-12-10 15:43               ` Stefan Monnier
2014-12-10 15:49                 ` Ted Zlatanov
2014-12-10 18:28                   ` Artur Malabarba
2014-12-10 19:00                     ` Ted Zlatanov
2014-12-10 19:09                   ` Stefan Monnier
2014-12-10 19:14                     ` Ted Zlatanov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).