[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] gv.el: minor change, cleaning up

From: Hu Lucius
Subject: [PATCH] gv.el: minor change, cleaning up
Date: Wed, 16 Jun 2021 05:06:36 +0000

When defining `gv-expander` of `alist-get`, the following binding
specification seems to have a redundant `setq` form.

   `(if ,p (setcdr ,p ,v)
      ,(funcall setter
                `(cons (setq ,p (cons ,k ,v))

Here `set-exp` expands to an s-_expression_ that updates the value
of an alist. `p` is a boolean that equals `(assq KEY ALIST)`
(or any other test function specified in the `alist-get` form).
`k` and `v` are KEY and VALUE respectively.

Evaluate `(macroexpand-all `(setf (alist-get key alist) value))` and
it returns the following:

  (let* () ;; /* bindings omitted */
     (if p
         (setcdr p v)
       (setq alist
             (cons (setq p
                         (cons key v))

It seems to me that `(setq p ..)` is unnecessary, i.e. we can simply

 (setq alist (cons (cons key v) alist)

This commit fixes that.

Signed-off-by: Lucius Hu <lebensterben@users.noreply.github.com>
 lisp/emacs-lisp/gv.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index f08f7ac115..cf6cae4fd8 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -407,7 +407,7 @@ alist-get
                        (let ((set-exp
                               `(if ,p (setcdr ,p ,v)
                                  ,(funcall setter
-                                           `(cons (setq ,p (cons ,k ,v))
+                                           `(cons (cons ,k ,v)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]