将字符串转换为Scheme中的代码 [英] Convert string to code in Scheme
问题描述
如何在PLT Scheme(不包含string->input-port
方法)中将字符串转换为相应的代码?例如,我要转换此字符串:
How do I convert a string into the corresponding code in PLT Scheme (which does not contain the string->input-port
method)? For example, I want to convert this string:
"(1 (0) 1 (0) 0)"
进入此列表:
'(1 (0) 1 (0) 0)
是否可以在不打开文件的情况下执行此操作?
Is it possible to do this without opening a file?
推荐答案
该方案具有用于从输入端口读取s表达式的过程read
,您可以使用string->input-port
将字符串转换为输入流.因此,您可以使用
Scheme has procedure read
for reading s-expressions from input port and you can convert a string to input stream with string->input-port
. So, you can read a Scheme object from a string with
(read (string->input-port "(1 (0) 1 (0) 0)"))
我没有安装Scheme,因此只能阅读从参考文献开始并没有进行实际测试.
I don't have Scheme installed, so I only read it from reference and didn't actually test it.
这篇关于将字符串转换为Scheme中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!