小编Bil*_*dri的帖子

使用scheme中的字符串获取变量值

我们怎样才能用方案语言中的字符串获取变量值,因为我们可以在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).

lisp scheme common-lisp

0
推荐指数
1
解决办法
343
查看次数

标签 统计

common-lisp ×1

lisp ×1

scheme ×1