File to List in SML

File to List in SML
 avatar
unknown
plain_text
4 years ago
584 B
2
Indexable
fun inputToList() =
let

        val infile = TextIO.openIn("input")
        fun getWord(infile) =
        let
                val x = TextIO.inputN(infile,1);
        in
                if x = " " orelse TextIO.endOfStream(infile) then "" else x ^ getWord(infile)
        end;

        fun concaneteWord(infile) =
        let
                val fine = TextIO.endOfStream(infile);
                val list = nil;
        in
                if fine then list else getWord(infile) :: list @ concaneteWord(infile)
        end;

in
        concaneteWord(infile)
end;
Editor is loading...