将字符串转换为Scheme中的代码 [英] Convert string to code in Scheme

查看:53
本文介绍了将字符串转换为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屋!

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