如何在MIT/GNU Scheme中读取文本文件? [英] How do I read a text file in MIT/GNU Scheme?

查看:65
本文介绍了如何在MIT/GNU Scheme中读取文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在经历SICP,我想应用到目前为止学到的一些概念.即积累,映射和过滤将帮助我提高工作效率.我主要使用CSV文件,并且我知道MIT/GNU方案不支持此文件格式.但这没关系,因为支持txt文件,因此我可以将CSV文件导出为txt文件.

I have been going through SICP and I would like to apply some of the concepts that I have learned so far. Namely accumulate, map and filter will help me be far more productive at work. I work mostly with CSV files and I know that MIT/GNU scheme does not support this file format. But that's ok as I can export the CSV file to txt file since txt files are supported.

现在,我阅读了本手册的第14节输入/输出",坦率地说,缺少具体示例并没有帮助我入门.因此,我希望你们中的一些人能给我一个良好的开端.我有一个文本文件foo.txt,其中包含变量和对国家/地区列表的观察值.我只想将此文件读入Scheme中并处理数据.感谢您的帮助.任何示例代码都会有所帮助.

Now I read Section 14 Input/Output of the manual and frankly the lack of specific examples is not helping me get started. Therefore I am hoping some of you could give me a head start. I have a text file, foo.txt, consisting of variables and observations for a list of countries. I just want to read this file into Scheme and manipulate the data. Thank you for your help. Any sample code would be helpful.

推荐答案

(call-with-input-file "my_file.txt"
  (lambda (port)
    (read port))) ; reads the file's contents

请参见 查看全文

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