From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Jan Jouleodov <jouleodov@protonmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 74870@debbugs.gnu.org
Subject: bug#74870: cl-labels and cl-flet don't create named blocks
Date: Sat, 21 Dec 2024 10:44:04 -0500 [thread overview]
Message-ID: <jwvo715f3h5.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <uQdY02Q2wEH6GjDVsxqfzl0XYD7LMOww5Hh7rsnRmNQMvGsi_ufbXyE_qxdnIYUzdd7tpdoZ2fnzqybCY43inQYY2f29tDMyPS8hFjrUjC0=@protonmail.com> (Jan Jouleodov's message of "Thu, 19 Dec 2024 00:55:34 +0000")
> Is there any reason why one would not want to *always* emulate the CL
> behavior in cl-lib? I could only think of a backward compatibility
> problem before CL was standardized, but I am not familiar with the time
> frame of cl-lib to know if that's really the case.
Could you try the patch below?
Stefan
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 65bc2cb9173..73741417383 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2096,15 +2096,22 @@ cl-flet
cl-declarations body)))
(let ((binds ()) (newenv macroexpand-all-environment))
(dolist (binding bindings)
- (let ((var (make-symbol (format "--cl-%s--" (car binding))))
- (args-and-body (cdr binding)))
- (if (and (= (length args-and-body) 1)
- (macroexp-copyable-p (car args-and-body)))
+ (let* ((var (make-symbol (format "--cl-%s--" (car binding))))
+ (args-and-body (cdr binding))
+ (args (car args-and-body))
+ (body (cdr args-and-body)))
+ (if (and (null body)
+ (macroexp-copyable-p args))
;; Optimize (cl-flet ((fun var)) body).
- (setq var (car args-and-body))
- (push (list var (if (= (length args-and-body) 1)
- (car args-and-body)
- `(cl-function (lambda . ,args-and-body))))
+ (setq var args)
+ (push (list var (if (null body)
+ args
+ (let ((parsed-body (macroexp-parse-body body)))
+ `(cl-function
+ (lambda ,args
+ ,@(car parsed-body)
+ (cl-block ,(car binding)
+ ,@(cdr parsed-body)))))))
binds))
(push (cons (car binding)
(lambda (&rest args)
@@ -2300,7 +2307,13 @@ cl-labels
var (macroexpand-all
(if (null sbody)
sargs ;A (FUNC EXP) definition.
- `(cl-function (lambda ,sargs . ,sbody)))
+ (let ((parsed-body
+ (macroexp-parse-body sbody)))
+ `(cl-function
+ (lambda ,sargs
+ ,@(car parsed-body)
+ (cl-block ,var
+ ,@(cdr parsed-body))))))
newenv)))))
(nreverse binds))
. ,(macroexp-unprogn
next prev parent reply other threads:[~2024-12-21 15:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 23:30 bug#74870: cl-labels and cl-flet don't create named blocks Jan Jouleodov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-14 16:54 ` Eli Zaretskii
2024-12-17 3:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 0:55 ` Jan Jouleodov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-21 15:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-21 16:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-21 16:24 ` Jan Jouleodov via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-19 16:28 ` Michael Heerdegen 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvo715f3h5.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=74870@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=jouleodov@protonmail.com \
--cc=monnier@iro.umontreal.ca \
/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 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.