Reu*_*aul 6 lisp closures scope lexical-scope
在lisp中我可以绑定绑定在这样的闭包中的自由变量......
(let ((x 1) (y 2) (z 3))
(defun free-variables () (+ x y z)))
(free-variables)
Run Code Online (Sandbox Code Playgroud)
结果是 ...
6
Run Code Online (Sandbox Code Playgroud)
我想知道的是,是否可以动态检查绑定闭包变量?
例如
(inspect-closure free-variables)
Run Code Online (Sandbox Code Playgroud)
导致类似......
((x 1) (y 2) (z 3))
Run Code Online (Sandbox Code Playgroud)
谢谢你
Common Lisp
只能从同一范围内的函数访问闭包的内部变量(参见Jeff的回答).即便是那些无法在某处查询这些变量.Common Lisp标准不提供此功能.
显然,在许多情况下,各个Common Lisp实现都知道如何获取这些信息.如果您在GNU Emacs的SLIME代码(Common Lisp开发环境)中查找示例,则检查和回溯功能的代码应提供该代码.开发想要展示这一点 - 对于用户/程序员,Common Lisp标准不提供该信息.