在DrScheme中的文件I / O [英] File I/O In DrScheme

查看:141
本文介绍了在DrScheme中的文件I / O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(读)从标准输入接收一个字符串,将其解析为s表达式,并返回该表达式。除了从文件中获取输入外,我该如何做同样的事情?

解决方案

以下任何一个:

b
$ b

 (调用输入文件foo读取)
(带有输入文件foo读取)

第一个将打开文件并应用 read 在打开的端口上读取一个值,最后关闭它。第二个是类似的,只不过它在没有参数的情况下在从文件中读取当前输入的动态上下文中应用函数。还有其他一些方法可以做到这一点,但你需要问一个更具体的问题...

(顺便说一下,在目前的版本库,其中将很快发布为4.2.3,有一个新的文件 - >列表函数将会读取所有的sexpressions从文件中返回一个包含所有这些文件的列表。)


(read) takes in a string from stdin, parses it as an s-expression, and returns that expression. How do I do the exact same thing, except taking input from a file?

解决方案

Any of these:

(call-with-input-file "foo" read)
(with-input-from-file "foo" read)

The first will open the file and apply read on the open port to read a value and finally close it. The second is similar, except that it applies the function on no arguments in a dynamic context where the current input is read from the file. There are a bunch of other ways to do this, but you'll need to ask a more specific question...

(BTW, in the current repository version, which will be released as 4.2.3 soon, there is a new file->list function that will read all sexpressions from the file and return a list holding all of them.)

这篇关于在DrScheme中的文件I / O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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