tags:

views:

128

answers:

1

The following question is related SMLNJ. I am trying to write a function that when called, the text file would be read and each line will be placed into a list. I kept geting some syntax errors, could someone help me debug it please?

The following is the code i have:

fun readlist(infile: string) = let val ins = TextIO.openIn infile val l = TextIO.inputLine ins val list = (l::nil) fun createlist() = let val l = TextIO.inputLine ins

  in case l of
       NONE => (TextIO.closeIn ins)
     | SOME l => list = l::list; createlist()

in createlist() end

The following is the syntax error that i have: readlist.sml:11.48 Error: syntax error: inserting END uncaught exception Compile [Compile: "syntax error"]

raised at: ../compiler/Parse/main/smlfile.sml:15.24-15.46 ../compiler/TopLevel/interact/evalloop.sml:44.55

         ../compiler/TopLevel/interact/evalloop.sml:296.17-296.20
A: 

It sounds as if this is the same question as http://stackoverflow.com/questions/680916/looping-over-lines-of-a-text-file-in-sml-nj, which has a nice answer already.

Michael Norrish