unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: emacs-devel@gnu.org
Subject: Proposing "alist" macro
Date: Fri, 17 Aug 2018 20:57:07 -0500	[thread overview]
Message-ID: <CAO_b3FW+mXXg8N=J0qJXQjVvfBZanfy8zAUaURvMh_WS28zw-A@mail.gmail.com> (raw)

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.



             reply	other threads:[~2018-08-18  1:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-18  1:57 Adam Porter [this message]
2018-08-21 15:45 ` Proposing "alist" macro 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO_b3FW+mXXg8N=J0qJXQjVvfBZanfy8zAUaURvMh_WS28zw-A@mail.gmail.com' \
    --to=adam@alphapapa.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).