我们怎样才能用方案语言中的字符串获取变量值,因为我们可以在Common Lisp中实现这一点:
> (defvar s 3)
> S
> (symbol-value (intern "S"))
> 3
Run Code Online (Sandbox Code Playgroud)
我从闭包中访问父函数的参数.
编辑:我找到了这个解决方案,但我不能使用eval,因为它在顶层评估.寻找替代品.
(eval (string->symbol "s"))
Run Code Online (Sandbox Code Playgroud)
编辑2:我发现Common lisp代码也试图在全局空间中找到符号.所以这个问题基本上都适用于Lisps(Common Lisp,Scheme).