Read a file line by line: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Add Standard ML version)
Line 3,349: Line 3,349:
#.output(#.readline(f))
#.output(#.readline(f))
<</syntaxhighlight>
<</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}}==
=={{header|Tcl}}==