mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 01:04:43 +00:00
Estimated hours taken: 1 Branches: main Added a test case to ensure that main can be called recursively without any problems. It is also an additional IO test. tests/hard-coded/recursive_main.m: Test program that just echoes stdin. tests/hard-coded/recursive_main.inp: Some text input. tests/hard-coded/recursive_main.exp: The exact same text as recursive_main.inp. tests/hard-coded/Mmakefile: Added recursive_main to the enabled lists.
31 lines
529 B
Mathematica
31 lines
529 B
Mathematica
% All this program does is echo the input by recursively calling main to read
|
|
% and then write one char.
|
|
%
|
|
% It is useful both for ensuring that this recursion works ok, and as an IO
|
|
% test.
|
|
|
|
:- module recursive_main.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module io.
|
|
|
|
main -->
|
|
read_char(Result),
|
|
(
|
|
{ Result = ok(Char) },
|
|
write_char(Char),
|
|
main
|
|
;
|
|
{ Result = eof }
|
|
;
|
|
{ Result = error(Error) },
|
|
write_string(error_message(Error))
|
|
).
|