免责声明:我今天开始使用 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 response resp))
(cider-current-connection)
(cider-current-session)))
我的理解是
response
在 let*
的范围内从 lambda 函数调用时的子句......但显然不是。This also seem to be working in this code
所以我有点迷失为什么我会收到这个错误以及我应该怎么做。
最佳答案
您需要通过设置全局变量 lexical-binding
来指定词法绑定(bind)作为源文件中的文件局部变量。将这样的一行作为文件的第一行:
;;; -*- lexical-binding: t -*-
要么这样做,要么使用
lexical-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)))
使用词法变量,当您对文件进行字节编译时,会编译 lambda 形式。如果没有变量(即只有它的值),则不会编译 lambda 形式——它只是一个列表(带有 car
lambda
等)。
关于debugging - Elisp:符号作为变量的值在 let* 和 (lambda) 中是无效的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36314825/