免责声明:我今天开始使用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)))
我的理解是,当从lambda函数调用时response,在let*子句的范围内......但显然它不是.
所以我有点迷失为什么我得到这个错误以及我应该怎么做.
您需要通过将全局变量设置lexical-binding为源文件中的文件局部变量来指定词法绑定.把这样的一行作为文件的第一行:
;;;  -*- 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形式不会被编译 - 它只是一个列表(带有汽车lambda等).