【发布时间】:2013-05-28 04:55:27
【问题描述】:
我正在重新熟悉 Scheme,我遇到了一个问题,这可能反映了我的基本误解。
假设我在 Scheme 中执行以下操作(在这种情况下使用 Guile,但在 Chicken 中是相同的):
> (define x 5)
> x
5
> (string->symbol "x")
x
> (+ 5 (string->symbol "x"))
<unnamed port>:45:0: In procedure #<procedure 1b84960 at <current input>:45:0 ()>:
<unnamed port>:45:0: In procedure +: Wrong type: x
> (symbol? (string->symbol "x"))
#t
> (+ 5 x) ; here x is dereferenced to its value 5
10
> (+ 5 'x) ; here x is not dereferenced
<unnamed port>:47:0: In procedure #<procedure 1c7ba60 at <current input>:47:0 ()>:
<unnamed port>:47:0: In procedure +: Wrong type: x
我知道string->symbol 正在返回一个符号x,它被有效地引用了。但是,我无法弄清楚如何在以后的任何上下文中使用 string->symbol 返回的符号。如何让 Scheme 评估该符号?
为了说明我为什么要这样做的背景,我正在编写一个嵌入 Guile 的 C 程序。我希望能够通过 C 的名称访问 Guile 中定义的符号,例如使用 scm_from_*_symbol 或 scm_string_to_symbol。这些功能没有按我想象的方式工作的原因与我上面的核心问题有关。也许有更好的方法来做我想要对 Guile 做的事情,但这是一个不同的问题。现在我对上面的基本问题感兴趣。
【问题讨论】:
标签: scheme symbols evaluation guile