[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proposing "alist" macro
From: |
Adam Porter |
Subject: |
Proposing "alist" macro |
Date: |
Fri, 17 Aug 2018 20:57:07 -0500 |
Hi,
I've found the a-list function from the a.el library to be very
helpful for building alists, e.g. instead of:
#+BEGIN_SRC elisp
(let ((a 1)
(b 2))
(list (cons 'one a)
(cons 'two b)
(cons 'three 3)))
#+END_SRC
Or:
#+BEGIN_SRC elisp
(let ((a 1)
(b 2))
`((one . ,a)
(two . ,b)
(three . 3)))
#+END_SRC
I can write:
#+BEGIN_SRC elisp
(let ((a 1)
(b 2))
(a-list 'one a
'two b
'three 3))
#+END_SRC
However, a-list runs mapcar and seq-partition at runtime. Also, few
people have a.el installed, and people seem reluctant to install it.
So I'd like to propose this macro for addition to Emacs:
#+BEGIN_SRC elisp
(defmacro alist (&rest args)
"Build an association list from the keys and values in ARGS.
ARGS is a list of alternating keys and value forms, like a plist.
For example:
(alist 'one 1
\"TWO\" \"2\"
3 (nth 3 var))
Expands to:
(list (cons 'one 1)
(cons \"TWO\" \"2\")
(cons 3 (nth 3 var)))"
`(list ,@(cl-loop for (key value) on args by #'cddr
collect `(cons ,key ,value))))
#+END_SRC
If this is acceptable, I'd be happy to provide a patch with whatever
changes are desired.
Thanks.
- Proposing "alist" macro,
Adam Porter <=