unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Wing Hei Chan <whmunkchan@outlook.com>
Cc: 56739@debbugs.gnu.org
Subject: bug#56739: 29.0.50; `cl-psetq' and `cl-psetf' fail to recognize symbol macros
Date: Wed, 03 Aug 2022 02:20:55 +0200	[thread overview]
Message-ID: <87y1w6xjmg.fsf@web.de> (raw)
In-Reply-To: <8735eeyz7e.fsf@web.de> (Michael Heerdegen's message of "Wed, 03 Aug 2022 01:59:01 +0200")

[-- Attachment #1: Type: text/plain, Size: 81 bytes --]

Hello,

I think we can fix this (both cases mentioned) similarly as in cl-letf:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP-Fix-symbol-macros-used-in-cl-psetf-Bug-56739.patch --]
[-- Type: text/x-diff, Size: 1447 bytes --]

From 29ea21a751ab6e71b2fb34c781131e31fc7b950d Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Wed, 3 Aug 2022 02:06:16 +0200
Subject: [PATCH] WIP: Fix symbol macros used in cl-psetf (Bug#56739)

---
 lisp/emacs-lisp/cl-macs.el | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 78d19db479..f3051752ba 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2653,12 +2653,17 @@ cl-psetf

 \(fn PLACE VAL PLACE VAL ...)"
   (declare (debug setf))
-  (let ((p args) (simple t) (vars nil))
+  (let ((p args) (simple t) (vars nil)
+        (smacros (alist-get :cl-symbol-macros macroexpand-all-environment)))
     (while p
-      (if (or (not (symbolp (car p))) (cl--expr-depends-p (nth 1 p) vars))
-	  (setq simple nil))
-      (if (memq (car p) vars)
-	  (error "Destination duplicated in psetf: %s" (car p)))
+      (when (or (not (symbolp (car p)))
+                (assq (car p) smacros)
+                (and (symbolp (nth 1 p))
+                     (assq (nth 1 p) smacros))
+                (cl--expr-depends-p (nth 1 p) vars))
+	(setq simple nil))
+      (when (memq (car p) vars)
+	(error "Destination duplicated in psetf: %s" (car p)))
       (push (pop p) vars)
       (or p (error "Odd number of arguments to cl-psetf"))
       (pop p))
--
2.30.2


[-- Attachment #3: Type: text/plain, Size: 353 bytes --]


But I'm not a fan of symbol macros any more: the concept sounds nice
first, but actually you only save one pair of parens when coding while
they introduce a special case that one always has too keep in mind for
macro expansions: any symbol might not just be a symbol.

I guess this is not the only place where they are not handled correctly.

Michael.

  reply	other threads:[~2022-08-03  0:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-24 12:12 bug#56739: 29.0.50; `cl-psetq' and `cl-psetf' fail to recognize symbol macros Wing Hei Chan
2022-08-02  2:41 ` Michael Heerdegen
2022-08-02 23:59 ` Michael Heerdegen
2022-08-03  0:20   ` Michael Heerdegen [this message]
2022-09-05 19:14     ` Lars Ingebrigtsen
2022-09-06  1:29       ` Michael Heerdegen
2022-09-06  2:22     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 18:31       ` Stefan Kangas
2023-09-08  3:07         ` Michael Heerdegen
2023-09-09  6:12           ` Michael Heerdegen
2023-09-09  7:08             ` Gerd Möllmann
     [not found]               ` <f49326d6-85e2-4fed-83ae-815a82cefe30@outlook.com>
2023-09-09  8:03                 ` Wing Hei Chan
2023-09-09  9:24                   ` Gerd Möllmann
2023-09-09 15:42               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-09 16:33                 ` Gerd Möllmann
2022-09-06  2:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=87y1w6xjmg.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=56739@debbugs.gnu.org \
    --cc=whmunkchan@outlook.com \
    /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).