Debugging Elisp:Symbol';s值作为变量是空的,带有let*和(λ)
免责声明:我今天开始和elisp闲逛 我真的很想知道我得到了以下错误:Debugging Elisp:Symbol';s值作为变量是空的,带有let*和(λ),debugging,emacs,elisp,lexical-scope,Debugging,Emacs,Elisp,Lexical Scope,免责声明:我今天开始和elisp闲逛 我真的很想知道我得到了以下错误: Symbol's value as variable is void: response 使用以下代码: (let* ((response (cons 'dict nil))) (nrepl-request:eval code (lambda (resp) (print resp (get-buffer "*sub-process*")) (nrepl--merge respon
Symbol's value as variable is void: response
使用以下代码:
(let* ((response (cons 'dict nil)))
(nrepl-request:eval
code
(lambda (resp)
(print resp (get-buffer "*sub-process*"))
(nrepl--merge response resp))
(cider-current-connection)
(cider-current-session)))
我的理解是,当从lambda函数调用时,response
在let*
子句的范围内。。。但显然不是这样
因此,我有点不明白为什么会出现这个错误,以及我应该如何处理它。您需要通过将全局变量
词法绑定设置为源文件中的文件局部变量来指定词法绑定。将这样一行作为文件的第一行:
;;; -*- lexical-binding: t -*-
要么这样做,要么使用词法let*
而不是let*
或者,如果在调用匿名函数时不需要变量response
作为变量,也就是说,如果在定义函数时只需要变量的值,则可以使用以下方法:
(let* ((response (cons 'dict nil)))
(nrepl-request:eval
code
`(lambda (resp)
(print resp (get-buffer "*sub-process*"))
(nrepl--merge ',response resp)) ; <===== Substitute value for variable
(cider-current-connection)
(cider-current-session)))
(let*((响应(cons'dict nil)))
(nrepl请求:eval)
代码
`(兰姆达(resp)
(打印响应(获取缓冲区“*子进程*”)
(nrepl--merge',response resp));使用动态绑定时,response
的值在定义lambda时被绑定,但显然该函数没有在同一范围内被调用,因此response
在该点上没有值(当然,除非它在其他地方被绑定)。