all messages for Emacs-related lists mirrored at yhetil.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

* Re: Proposing "alist" macro
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Clément Pit-Claudel @ 2018-08-21 15:45 UTC (permalink / raw)
  To: emacs-devel

On 2018-08-17 21:57, Adam Porter wrote:
> If this is acceptable, I'd be happy to provide a patch with whatever
> changes are desired.

LGTM, but couldn't it be a function?



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

* Re: Proposing "alist" macro
  2018-08-21 15:45 ` Clément Pit-Claudel
@ 2018-09-05 12:41   ` Van L
  2018-09-05 13:06     ` Noam Postavsky
  0 siblings, 1 reply; 7+ messages in thread
From: Van L @ 2018-09-05 12:41 UTC (permalink / raw)
  To: Emacs-Devel devel


> LGTM, but couldn't it be a function?

A macro does not needlessly eval the args.




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

* Re: Proposing "alist" macro
  2018-09-05 12:41   ` Van L
@ 2018-09-05 13:06     ` Noam Postavsky
  2018-09-05 13:16       ` Van L
  2018-09-06  5:52       ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Noam Postavsky @ 2018-09-05 13:06 UTC (permalink / raw)
  To: Van L; +Cc: Emacs-Devel devel

On 5 September 2018 at 08:41, Van L <van@scratch.space> wrote:
>
>> LGTM, but couldn't it be a function?
>
> A macro does not needlessly eval the args.

The proposed macro expansions do eval all the args.



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

* Re: Proposing "alist" macro
  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
  1 sibling, 1 reply; 7+ messages in thread
From: Van L @ 2018-09-05 13:16 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Emacs-Devel devel


>> 
>>> LGTM, but couldn't it be a function?
>> 
>> A macro does not needlessly eval the args.
> 
> The proposed macro expansions do eval all the args.

The eval occurs after the macro expansion, right? that is why there is the defmacro.


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

* Re: Proposing "alist" macro
  2018-09-05 13:16       ` Van L
@ 2018-09-05 14:05         ` Noam Postavsky
  0 siblings, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2018-09-05 14:05 UTC (permalink / raw)
  To: Van L; +Cc: Emacs-Devel devel

On 5 September 2018 at 09:16, Van L <van@scratch.space> wrote:

>>>> LGTM, but couldn't it be a function?
>>>
>>> A macro does not needlessly eval the args.
>>
>> The proposed macro expansions do eval all the args.
>
> The eval occurs after the macro expansion, right? that is why there is the defmacro.

Correct, the expressions passed to the macro are evaluated exactly
once at runtime. Exactly the same as if it was a defun.



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

* Re: Proposing "alist" macro
  2018-09-05 13:06     ` Noam Postavsky
  2018-09-05 13:16       ` Van L
@ 2018-09-06  5:52       ` Richard Stallman
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2018-09-06  5:52 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: van, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > The proposed macro expansions do eval all the args.

Do they unconditionally eval all the args once and only once
in the order that they are written in the call?
If so, there is no need for a macro, so you could use
a function or defsubst.

-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





^ 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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.