Today I discovered that if you re-evaluate a defun using
eval-defun (C-M-x) in a buffer with
lexical-binding set to
t, the defun is recreated as an ordinary lambda, not a closure.
For example, after you evaluate this file:
;;; -*- lexical-binding: t; -*- (defun foo (x) (lambda (y) (+ x y)))
(symbol-function 'foo) returns
(closure (t) (x) (function (lambda (y) (+ x y))))
But if you put point in the body of the function, press C-M-x, and evaluate
(symbol-function 'foo) again, you get:
(lambda (x) (function (lambda (y) (+ x y))))
Certainly not the same thing, and in fact it throws a
void-variable error when you call the returned function, if
x is not globally bound.
Is this the intended behavior? Do I just need to remember not to use
eval-defun but rather
eval-buffer whenever I modify a function in a file where
I'm using Emacs 184.108.40.206.