Subject: bug#59872: cl-labels and cl-flet do not comply with the documentation

From: Rafael D Sorkin <[email-masked]>
Date: Wed, 7 Dec 2022 01:01:26 -0500 (EST)

Hi,

The documentation that I received along with emacs 28.2 says
about `cl-flet' that 

  "... the function body is enclosed in an implicit block as if by `cl-defun'".  

(This is from     
   File: cl.info,  Node: Function Bindings,  Next: Macro Bindings,  Prev: Dynamic Bindings,  Up: Variable Bindings
   4.3.2 Function Bindings
   -----------------------)

I expected this behavior precisely because of the parallel with
`cl-defun', as well as the connotation of the prefix "cl-"
itself, which leads on to expect that `cl-flet' and `cl-labels'
would act like their CL counterparts.

However, as far as I can tell, neither of these functions
actually creates an implicit named block, as claimed.
Below is the evidence (from emacs 26.3, but 28.2 is similar).
One sees that only `flet' works, but it has been declared as
"obsolete".

Thanks,
Rafael

emacs-version                                              ; 26.3
(require 'cl-lib)                                          ; cl-lib

(flet     ((tester () (return-from tester 3)))   (tester)) ; 3
(labels   ((tester () (return-from tester 3)))   (tester)) ; No catch for tag: --cl-block-tester--, 3
(cl-flet  ((tester () (return-from tester 3)))   (tester)) ; No catch for tag: --cl-block-tester--, 3
(cl-labels((tester () (return-from tester 3)))   (tester)) ; No catch for tag: --cl-block-tester--, 3

(Macroexpand '(cl-labels ((tester () (return-from tester 3))))) ; (let (#:--cl-tester--) (setq #:--cl-tester-- (function (lambda nil (throw (quote --cl-block-tester--) 3)))))

(Macroexpand '(cl-flet   ((tester () (return-from tester 3))))) ; (let* ((#:--cl-tester-- (cl-function (lambda nil (return-from tester 3))))) (progn))

(Macroexpand '(labels  ((tester () (return-from tester 3))))) ; (progn (defvar #:--cl---cl-tester----) (let ((#:--cl---cl-tester---- nil)) (let* ((#:v (quote #:--cl---cl-tester----))) (set #:v (function (lambda nil (throw (quote --cl-block-tester--) 3)))))))

(Macroexpand '(flet     ((tester () (return-from tester 3))))) ; (let* ((#:vnew (cl-function (lambda nil (cl-block tester (return-from tester 3))))) (#:old (symbol-function (quote tester)))) (unwind-protect (fset (quote tester) #:vnew) (fset (quote tester) #:old)))

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 Rafael Sorkin
 Perimeter Institute for Theoretical Physics
 31 Caroline Street North
 Waterloo, ON  N2L 2Y5
 Canada
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-