tags:

views:

307

answers:

3

Hi, i am a newbie learning sml and the question i am thrown with involves IO functions that i have no idea how it works even after reading it. Here is the 2 questions that i really need help with to get me started, please provide me with codings and some explaination, i will be able to 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 assigning 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 isnt 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 helping 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 stucked trying to read from the txt file and appending it to a list, I am able to do it for a single line but 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;

+1  A: 

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.

Norman Ramsey
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.
OK, I've added some suggestions about what functions to use. They are all in SML/NJ, at least the one on my machine, which is version 110.67.
Norman Ramsey
Thx for the functions, its helpful. can I ask for some explanation on the fun something(a : something) = let val a = a +1 in endI dont really understand how the "let", "in", "end" works, is there a webby to read about on them?
+1  A: 

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

i can confirm that the use "file.sml" function was not taught, and the TEXTIO things are not taught also.The things that are taught are mostly val a = something, list, fun something(a,b)= something; , not anything out of courseguide. labs and lect shown is by typing in cmd and not use "file.sml"
A: 

OMG UNCLE LEE IS STALKING US!!