smlnj listdir 问题

发布于 2024-07-15 01:23:58 字数 716 浏览 7 评论 0原文

我是一个学习sml的新手,给我的问题涉及到我不明白的IO函数。 这是我真正需要帮助才能开始的两个问题,请为我提供代码和一些解释,我将能够使用针对其他问题给出的代码进行试验和错误。

Q2) readlist(filename) 读取文件名列表(每个文件名都是由 (Q1) 中的 listdir 生成的,并将它们组合成一个大列表。 (从 Q1 中的文本文件中读取,然后将内容分配到包含所有信息的 1 个大列表中)

事情是,我只从学校讲师的介绍部分了解到,甚至没有显示系统输入或输出示例,连“使用文件”功能都没有教。 如果任何了解 sml 的人看到此内容,请帮忙。 感谢所有努力帮助我的人。

感谢您的回复,目前我正在使用 SMLNJ 尝试执行此操作。 基本上,Q1 要求我将提供的“目录名”的目录文件列出到“文件名”中的文本文件中。 Q2 要求我从“文件名”文本文件中读取内容,然后将内容放入一个大列表中。

顺便说一句,如果你们只看到这篇文章,请也尝试提出问题。 目前,我一直在尝试从 txt 文件中读取并将其附加到列表中,我可以对一行执行此操作,但现在尝试对整个文件执行此操作:

fun readlist(infile : string) =
let val ins = TextIO.openIn infile

fun listing() = 
TextIO.inputLine ins;

in listing()
end;
TextIO.closeIn;

I am a newbie learning sml and the question I am given involves IO functions that I do not understand.
Here are the 2 questions that I really need help with to get me started, please provide me with code and some explanation, I will be able to use trial and error with the code given for the other questions.

Q2) readlist(filename) which reads a list of filenames (each of which were produced by listdir in (Q1) and combines them into one large list.
(reads from the text file in Q1 and then assigns the contents into 1 big list containing all the information)

Thing is, I only learned from the lecturer in school on the introduction section, there isn't even a system input or output example shown, not even the "use file" function is taught. if anyone that knows sml sees this, please help. Thanks to anyone who took the effort to help me.

Thanks for the reply, current I am using SMLNJ to try and do this. Basically, Q1 requires me to list the directory's files of the "directoryname" provided into a text file in "filename". The Q2 requires me to read from the "filename" text file and then place the contents into one large list.

BTW, if you people only kept seeing this post, please try and ask questions also. Currently i am stuck trying to read from the txt file and appending it to a list, I am able to do it for a single line but am now trying to do it for the whole file:

fun readlist(infile : string) =
let val ins = TextIO.openIn infile

fun listing() = 
TextIO.inputLine ins;

in listing()
end;
TextIO.closeIn;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南…巷孤猫 2024-07-22 01:23:58

我很难弄清楚你想问什么问题。

您询问的函数不属于机器学习标准基础库的一部分。 如果你要编写它们,如果没有某种 Posix 模块,你将会遇到困难。 你可以告诉你的老师我不喜欢这项作业。

莫斯科 ML 包含一个 listDir 函数,该函数非常简单:

- load "Mosml";
> val it = () : unit
- Mosml.listDir ".";
> val it = ["natural-semantics.djvu", "natural-semantics.pdf"] : string list
- 

要获得更多帮助,请更清楚您要问的内容。


编辑:由于这是一个家庭作业问题,我不应该只给你答案,但一些有用的函数包括来自的openDirreadDircloseDir OS.Filesys 结构。 这些将告诉您目录中有什么。 然后,要读取和写入文件,您需要 TextIO

您会发现标准基础库文档是必不可少的。

It is very hard for me to make out what questions you are trying to ask.

The functions you ask about are not part of the Standard Basis Library for ML. If you are supposed to write them, you are going to have a hard time without some kind of Posix module. You can tell your instructor I didn't care for this assignment.

Moscow ML contains a listDir function which is admirably simple:

- load "Mosml";
> val it = () : unit
- Mosml.listDir ".";
> val it = ["natural-semantics.djvu", "natural-semantics.pdf"] : string list
- 

To get more help, please be a little clearer what you are asking.


EDIT: Since it's a homework question I shouldn't just give you the answer, but some useful functions includeopenDir, readDir, and closeDir from the OS.Filesys structure. These will tell you what's in the directory. Then to read and write files you'll want TextIO.

You'll find the Standard Basis Library documentation indispensible.

比忠 2024-07-22 01:23:58

你确定我没教你?
你欠我一份鸡肉馅饼。

You sure i didn't teach u?
u owe me one chicken pie.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文