Read a file line by line: Difference between revisions

Add Standard ML version
imported>Arakov
(Add Standard ML version)
 
(One intermediate revision by one other user not shown)
Line 3,349:
#.output(#.readline(f))
<</syntaxhighlight>
 
=={{header|Standard ML}}==
Gets the lines of a file as a list of strings with trailing newline removed.
 
<syntaxhighlight lang="sml">fun readLines string =
let
val strm = TextIO.openIn path
fun chomp str =
let
val xstr = String.explode str
val slen = List.length xstr
in
String.implode(List.take(xstr, (slen-1)))
end
fun collectLines ls s =
case TextIO.inputLine s of
SOME(l) => collectLines (chomp l::ls) s
| NONE => ls
in
List.rev (collectLines [] strm) before TextIO.closeIn strm
end
</syntaxhighlight>
 
=={{header|Tcl}}==
Line 3,799 ⟶ 3,821:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
var lines = [] // store lines read
23

edits