[mercury-users] Re: Mercury Tutorial / Functions
Goncalo Jorge Coelho e Silva
l10454 at alunos.uevora.pt
Fri Apr 25 01:31:54 AEST 2003
> I *strongly* suggest you don't use DCG notation (as you have for main/2)
> until you're more familiar with how IO and uniqueness work.
I forgot to mention on my last mail, I re-arranged the main call,
so as not to use DCGs:
:- module inter.
:- interface.
:- import_module io.
:- import_module string.
:- import_module list.
%:- import_module exception.
:- pred main(io__state, io__state). :- mode main(di, uo) is det.
:- pred read_strings(list(string), io__state, io__state).
:- mode read_strings(out, di, uo) is det.
:- pred read_strings_2(list(string), list(string), io__state, io__state).
:- mode read_strings_2(in, out, di, uo) is det.
:- implementation.
:- import_module exception.
%main --> main(IO0,IO):-
read_strings(Ss,IO0,IO).
read_strings(Ss, IO0, IO) :-
read_strings_2([], Ss, IO0, IO).
read_strings_2(RevSs, Ss, IO0, IO) :-
io__read_line_as_string(Result, IO0, IO1),
(
Result = ok(S),
%io__write_string(S,IO0, IO1),
IO = IO1,
Ss = [S | RevSs],
read_strings_2([S | RevSs], Ss, IO1, IO)
;
Result = eof,
Ss = list__reverse(RevSs)
;
Result = error(_),
exception__throw(Result)
).
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list