Subject: bug#65344: 28.2; Unable to Edebug cl-flet form which uses argument destructuring

From: Gerd Möllmann <[email-masked]>
Date: Sun, 20 Aug 2023 07:32:50 +0200

On 20.08.23 05:57, Michael Heerdegen wrote:
> Gerd Möllmann <[email-masked]> writes:
> 
>> (debug ((&rest [&or (&define [&name symbolp "@cl-flet@"]
>> 			[&name [] gensym] ;Make it unique!
>> 			cl-lambda-list
>> 			cl-declarations-or-string
>> 			[&optional ("interactive" interactive)]
>> 			def-body)
>> 		    (&define [&name symbolp "@cl-flet@"]
>> 			[&name [] gensym] ;Make it unique!
>> 			def-body)])
> 
>> The second &define is for the (FN EXPR) bindings.  It comes after the
>> &define for "normal" function bindings because because, for some
>> reason, apparently the second &define also matches the other case.
> 
> That's because you use 'def-body' which matches any number of body
> expressions.  I think this is not correct: we are expecting a single
> form.

Ah, I see.  Thanks.

> 
> Apart from that: yes, something like this... I did not yet understand
> the &name magic.
> 
> And i wonder whether we should apply the distributive law and factor out
> the first few identical specs inside the &or.

I'd rather keep the two separate, I must admit.  Basically, bacause the 
first case it the important one, and the second I find obscure.

I also checked now what's up with functions whose name is (setf ...), 
which is valid CL.  That's not supported in ELisp, it seems, so I 
changed the debug spec of cl-defun accordingly in the attached patch.

If this looks good, I'd bring that to master, unless Eli wants it in 29.

modified   lisp/emacs-lisp/cl-macs.el
@@ -389,7 +389,7 @@ cl-defun
 \(fn NAME ARGLIST [DOCSTRING] BODY...)"
   (declare (debug
             ;; Same as defun but use cl-lambda-list.
-            (&define [&name sexp]   ;Allow (setf ...) additionally to symbols.
+            (&define [&name symbolp]
                      cl-lambda-list
                      cl-declarations-or-string
                      [&optional ("interactive" interactive)]
@@ -2064,13 +2064,15 @@ cl-flet
 
 \(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
   (declare (indent 1)
-           (debug ((&rest [&or (symbolp form)
-                               (&define [&name symbolp "@cl-flet@"]
+           (debug ((&rest [&or (&define [&name symbolp "@cl-flet@"]
                                         [&name [] gensym] ;Make it unique!
                                         cl-lambda-list
                                         cl-declarations-or-string
                                         [&optional ("interactive" interactive)]
-                                        def-body)])
+                                        def-body)
+                               (&define [&name symbolp "@cl-flet@"]
+                                        [&name [] gensym] ;Make it unique!
+                                        def-form)])
                    cl-declarations body)))
   (let ((binds ()) (newenv macroexpand-all-environment))
     (dolist (binding bindings)