如何评估从Scheme中的函数返回的符号? [英] How do I evaluate a symbol returned from a function in Scheme?

查看:116
本文介绍了如何评估从Scheme中的函数返回的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Scheme不熟悉,我遇到了一个问题,该问题可能反映了我的基本误会.

I'm refamiliarizing myself with Scheme and I've hit a problem that is probably reflecting a fundamental misunderstanding on my part.

假设我在Scheme中执行以下操作(在这种情况下使用Guile,但在Chicken中是相同的):

Say I do the following in Scheme (using Guile in this case but it's the same in 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评估该符号?

I understand that string->symbol is returning a symbol, x, which is effectively quoted. However, I cannot figure out how to use the symbol returned by string->symbol in any later context. How can I have Scheme evaluate that symbol?

要说明为什么要执行此操作,是因为我正在编写带有嵌入式Guile的C程序.我希望能够使用例如scm_from_*_symbolscm_string_to_symbol从C中访问在Guile中按名称定义的符号.这些功能无法按我认为的方式工作的原因与我上面的核心问题有关.也许有一种更好的方法可以完成我对Guile的处理,但这是一个不同的问题.现在,我对上面的基本问题感兴趣.

To give a background on why I want to do this, it's that I'm writing a C program with embedded Guile. I would like to be able to be able to access symbols defined in Guile by name from C, using for example scm_from_*_symbol or scm_string_to_symbol. The reasons these functions aren't working the way I thought they would is related to my core question above. Perhaps there's a better way to do what I want to do with Guile, but that's a different question. Right now I'm interested in the fundamental question above.

推荐答案

您应该阅读您需要eval,可能还需要interaction-environment

我建议阅读著名的 SICP 和Queinnec的

I recommend reading the famous SICP and Queinnec's Lisp In Small Pieces

这篇关于如何评估从Scheme中的函数返回的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆