12

After switching from Emacs 25 to Emacs 28 I started to get this warning message during the loading of my custom settings

.emacs.d/init.el: Warning: (lambda nil \.\.\.) quoted with ' rather than with #'

I upgraded all installed packages and everything works as expected, but I don't know what is this.

5
  • 5
    It's a warning, not an error, so you can ignore it if you want, but you should probably fix it, if only to avoid being nagged. Search in your init.el for a single quote quoting a lambda expression: '(lambda - you can just follow the recommendation of the warning and change it to #'(lambda - but lambda expressions are self evaluating in any case, so there is probably no reason to quote it at all. However, you might want to post the relevant snippet from your init.el file in your question and ask how to fix it (if a fix is necessary).
    – NickD
    Commented Oct 28, 2022 at 15:23
  • 7
    Effectively, the Emacs compiler can compile #'(lambda ...) to byte code, whereas '(lambda ...) can be a plain lisp list which just happen to start with the atom lambda, so the compiler is not allowed to compile it. Commented Oct 28, 2022 at 20:24
  • 1
    thanks. I corrected all '(lambda to #'(lambda in the init.el file and now the error disappeared. I wonder why this didn't happen with Emacs 25. Probably it was more tollerant (?) Commented Nov 2, 2022 at 8:42
  • 2
    Please note that (lambda ...) is a self-quoting form (using function-quoting) such that it is the same thing as #'(lambda ...) -- but different to '(lambda ...) (the latter being a regular quote rather than a function quote). So the best fix is to not use any explicit quoting, and then function-quoting is used automatically.
    – phils
    Commented Sep 10 at 13:30
  • 1
    "I wonder why this didn't happen with Emacs 25" -- Emacs 25 simply didn't look for the problem. The problem itself was still present -- your '(lambda ...) forms could no more be byte-compiled in Emacs 25 than they can in your current version.
    – phils
    Commented Sep 10 at 13:33

1 Answer 1

4

Reposting the comments as an answer as it was answered in comments:

It's a warning, […] but you should probably fix it […]. Search in your init.el for a single quote quoting a lambda expression: '(lambda - you can just follow the recommendation of the warning and change it to #'(lambda - but lambda expressions are self evaluating in any case, so there is probably no reason to quote it at all.

Effectively, the Emacs compiler can compile #'(lambda ...) to byte code, whereas '(lambda ...) can be a plain lisp list which just happen to start with the atom lambda, so the compiler is not allowed to compile it.

Please note that (lambda ...) is a self-quoting form (using function-quoting) such that it is the same thing as #'(lambda ...) -- but different to '(lambda ...) (the latter being a regular quote rather than a function quote). So the best fix is to not use any explicit quoting, and then function-quoting is used automatically.

Emacs documentation also mentions that at the bottom of this page.

4
  • Any idea where this is documented? Commented Sep 10 at 2:45
  • 1
    This is documented in Emacs Lisp reference: gnu.org/software/emacs/manual/html_node/elisp/… Commented Sep 10 at 2:56
  • @BrunoBEAUFILS thanks, added to the answer. Please note that the answer is a "community wiki", so you and everyone can freely edit it.
    – Hi-Angel
    Commented Sep 10 at 4:44
  • 2
    An even better solution is "change it to (lambda" rather than "change it to #'(lambda", c.f. comments on the question by @phils.
    – mtraceur
    Commented Sep 10 at 20:40

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.