The following code seems fine semantically:

;; -*- lexical-binding: nil; -*-
(named-let f ((_ '(1)))
  (dolist (paren-1-paren _)
    (f ())))

Why does it throw an error?

(Is this a bug? If so, I will report it.)

Reported as bug#64290.

  • @Drew: This question essentially has nothing to do with [list]; I'm just using it as an example. You can try this: (named-let f ((n 1)) (dotimes (i n) (f 0))). |||| So I removed tag[list].
    – shynur
    Jun 25, 2023 at 21:55
  • You're right. Thx.
    – Drew
    Jun 26, 2023 at 1:31

1 Answer 1


Refer to C-hig (cl)Function Bindings:

-- Macro: cl-labels (bindings...) forms...
The ‘cl-labels’ form is like ‘cl-flet’, except that the function bindings can be recursive. The scoping is lexical, but you can only capture functions in closures if ‘lexical-binding’ is ‘t’. *Note (elisp)Closures::, and *note (elisp)Using Lexical Binding::.

Which is relevant because your code expands to:

           (paren-1-paren _)
         (f nil))))

And ultimately:

   (setq --cl-f--
                 ((--dolist-tail-- _)
               (while --dolist-tail--
                 (setq paren-1-paren
                       (car --dolist-tail--))
                 (funcall --cl-f-- nil)
                 (setq --dolist-tail--
                       (cdr --dolist-tail--))))))

In which we can see specifically where that error would occur in the absence of lexical binding.

As the recursive call seems like a standard property of named-let I suggest you raise a documentation bug to suggest that it should indicate the lexical-binding requirement (which is maybe implicitly present in the existing reference to Scheme -- but only if you know something about Scheme).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.