March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
4
Task/File-IO/Frink/file-io.frink
Normal file
4
Task/File-IO/Frink/file-io.frink
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
contents = read["file:input.txt"]
|
||||
w = new Writer["output.txt"]
|
||||
w.print[contents]
|
||||
w.close[]
|
||||
40
Task/File-IO/Mercury/file-io.mercury
Normal file
40
Task/File-IO/Mercury/file-io.mercury
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
:- module file_io.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
main(!IO) :-
|
||||
io.open_input("input.txt", InputRes, !IO),
|
||||
(
|
||||
InputRes = ok(Input),
|
||||
io.read_file_as_string(Input, ReadRes, !IO),
|
||||
(
|
||||
ReadRes = ok(Contents),
|
||||
io.close_input(Input, !IO),
|
||||
io.open_output("output.txt", OutputRes, !IO),
|
||||
(
|
||||
OutputRes = ok(Output),
|
||||
io.write_string(Output, Contents, !IO),
|
||||
io.close_output(Output, !IO)
|
||||
;
|
||||
OutputRes = error(OutputError),
|
||||
print_io_error(OutputError, !IO)
|
||||
)
|
||||
;
|
||||
ReadRes = error(_, ReadError),
|
||||
print_io_error(ReadError, !IO)
|
||||
)
|
||||
;
|
||||
InputRes = error(InputError),
|
||||
print_io_error(InputError, !IO)
|
||||
).
|
||||
|
||||
:- pred print_io_error(io.error::in, io::di, io::uo) is det.
|
||||
|
||||
print_io_error(Error, !IO) :-
|
||||
io.stderr_stream(Stderr, !IO),
|
||||
io.write_string(Stderr, io.error_message(Error), !IO),
|
||||
io.set_exit_status(1, !IO).
|
||||
Loading…
Add table
Add a link
Reference in a new issue