File I/O In DrScheme

馋奶兔 提交于 2020-01-07 04:52:05

问题


(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?


回答1:


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.)



来源:https://stackoverflow.com/questions/1713332/file-i-o-in-drscheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!