我做了个实验,跟你的结果相同。
从打印顺序上看,url-retrieve
里的lambda
的执行是发生在你执行(setq buffer (current-buffer))
之后的。
参考Emacs Lisp RFM 12.10.1
Lexical binding is only available in the modern Emacs Lisp dialect. (*Note Selecting Lisp Dialect::.) A lexically-bound variable has “lexical scope”, meaning that any reference to the variable must be located textually within the binding construct. Here is an example
(let ((x 1)) ; ‘x’ is lexically bound.
(+ x 3))
⇒ 4
(defun getx ()
x) ; ‘x’ is used free in this function.
(let ((x 1)) ; ‘x’ is lexically bound.
(getx))
error→ Symbol's value as variable is void: x
Here, the variable ‘x’ has no global value. When it is lexically bound within a ‘let’ form, it can be used in the textual confines of that ‘let’ form. But it can not be used from within a ‘getx’ function called from the ‘let’ form, since the function definition of ‘getx’ occurs outside the ‘let’ form itself.
这里的lambda
如果没有被当作一个闭包处理,那么它里面的lexical binding应该是不生效的。所以我想应该传一个闭包进去,或者给它传参数进去。