unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Proposing "alist" macro
@ 2018-08-18  1:57 Adam Porter
  2018-08-21 15:45 ` Clément Pit-Claudel
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Porter @ 2018-08-18  1:57 UTC (permalink / raw)
  To: emacs-devel

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.



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

end of thread, other threads:[~2018-09-06  5:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-18  1:57 Proposing "alist" macro Adam Porter
2018-08-21 15:45 ` Clément Pit-Claudel
2018-09-05 12:41   ` Van L
2018-09-05 13:06     ` Noam Postavsky
2018-09-05 13:16       ` Van L
2018-09-05 14:05         ` Noam Postavsky
2018-09-06  5:52       ` Richard Stallman

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