Stefan Monnier writes: > I think "the right way" would be for the `cl-flet` implementation to use > a `cl--expand-flet` function returning which functions are used > and which aren't. > > Then we could use it here without such duplication, *and* we could use > it in `cl-flet` to emit warnings about unused functions. > > WDYT? I agree. I think the root of the problem is, ~cl-flet~ is generally not implemented well. Feels like it was implemented in a rush. - (func exp) is non-standard and ad-hoc. Do you happen to remember, maybe it was invented solely for ~cl--generic-lambda~? - (func exp) definition form is described incorrectly in the docstring: it should be (FUNCTION-NAME SYMBOL) and so on; this also affects cl-macrolet docstring which claims it's “like cl-flet” but in fact it's not as it doesn't support this definition form - ~cl-flet~ with invalid function names should error but it doesn't I implemented ~cl--expand-flet~ but I felt simply returning a list of used symbols would be just another ad-hoc addition so I decided to instead add an interface to execute arbitrary code during macroexpansion. It took longer than I expected but I'm satisfied with the result. I'll open a standalone bug (my implementation happens to fix some outstanding issues); when changes are (hopefully) merged, we'll continue on with this one. Quick reference: if all goes well, the definition of ~cl--generic-lambda~ is to become #+begin_example emacs-lisp .. (let* ((parsed-body (macroexp-parse-body body)) uses-cnm (cnm (make-symbol "cl--cnm")) (nmp (make-symbol "cl--nmp")) (nbody (cl--expand-flet macroenv (cdr parsed-body) (cl-call-next-method (push cnm uses-cnm) cnm) (cl-next-method-p (push nmp uses-cnm) nmp))) ;; FIXME: Optimize the case where call-next-method is ;; only called with explicit arguments. ) ..) #+end_example This involves a “macro” version of expand-flet; we'll see whether it's worth keeping alongside the corresponding function. If you can, please confirm my suspicion that (FUNC EXP) definitions were indeed invented solely for ~cl--generic-lambda~.