[m-rev.] trivial diff: update syntax in samples directory
Julien Fischer
juliensf at cs.mu.OZ.AU
Tue Mar 21 11:54:03 AEDT 2006
Estimated hours taken: 0.5
Branches: main
samples/*.m:
Use '.' as the module qualifier instead of '__'.
Use the new foreign language interface.
Fix minor formatting issues.
Use state variables syntax for passing around the I/O state.
Julien.
Index: calculator.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/calculator.m,v
retrieving revision 1.11
diff -u -r1.11 calculator.m
--- calculator.m 12 Aug 2005 04:50:36 -0000 1.11
+++ calculator.m 21 Mar 2006 00:21:49 -0000
@@ -95,8 +95,8 @@
term(Term) -->
( const(Const) ->
- { string__from_char_list(Const, ConstString) },
- { string__to_int(ConstString, Num) },
+ { string.from_char_list(Const, ConstString) },
+ { string.to_int(ConstString, Num) },
{ Term = number(Num) }
;
['('], expr(Term), [')']
@@ -116,4 +116,4 @@
digit(Char) -->
[Char],
- { char__is_digit(Char) }.
+ { char.is_digit(Char) }.
Index: e.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/e.m,v
retrieving revision 1.5
diff -u -r1.5 e.m
--- e.m 6 Mar 2006 00:47:46 -0000 1.5
+++ e.m 21 Mar 2006 00:21:05 -0000
@@ -22,25 +22,34 @@
%-----------------------------------------------------------------------------%
:- implementation.
-:- import_module int, list, require, char, string.
+
+:- import_module char.
+:- import_module int.
+:- import_module list.
+:- import_module require.
+:- import_module string.
% Default number of digits displayed (if this is not specified
% on the command line).
+ %
:- func default_digits = int.
default_digits = 1000.
% Change this for a base other than 10. Any integer between
% 2 and 36 makes sense.
+ %
:- func base = int.
base = 10.
% Number of columns on the terminal.
+ %
:- func columns = int.
columns = 78.
%-----------------------------------------------------------------------------%
% This is a simple implementation of an infinite lazy stream.
+ %
:- type int_stream
---> [int | int_stream]
; closure((func) = int_stream).
@@ -54,11 +63,13 @@
%-----------------------------------------------------------------------------%
% An infinite stream of ones.
+ %
:- func ones = (int_stream :: is_out) is det.
ones = [1 | closure((func) = ones)].
% All the digits of e in one stream.
+ %
:- func digits_of_e = (int_stream :: is_out) is det.
digits_of_e = next_digit(ones).
@@ -112,6 +123,7 @@
io.nl(!IO).
% Print out digits until we don't have any more.
+ %
:- pred main_2(int::in, int::in, int_stream::is_in, io::di, io::uo) is det.
main_2(Digits, Columns, closure(Func), !IO) :-
@@ -123,7 +135,7 @@
io.nl(!IO),
main_2(Digits, columns, [I | Is], !IO)
;
- char__det_int_to_digit(I, Digit),
+ char.det_int_to_digit(I, Digit),
io.write_char(Digit, !IO),
main_2(Digits - 1, Columns - 1, Is, !IO)
).
Index: eliza.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/eliza.m,v
retrieving revision 1.17
diff -u -r1.17 eliza.m
--- eliza.m 12 Aug 2005 04:50:36 -0000 1.17
+++ eliza.m 21 Mar 2006 00:21:23 -0000
@@ -16,7 +16,7 @@
:- interface.
:- import_module io.
-:- pred main(io :: di, io :: uo) is det.
+:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: expand_terms.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/expand_terms.m,v
retrieving revision 1.4
diff -u -r1.4 expand_terms.m
--- expand_terms.m 12 Aug 2005 04:50:36 -0000 1.4
+++ expand_terms.m 21 Mar 2006 00:43:59 -0000
@@ -1,7 +1,5 @@
%-----------------------------------------------------------------------------%
-:- module expand_terms.
-
% Emulation of Prolog's expand_term/term_expansion mechanism.
% This program provides pre-processing of Mercury programs,
% using an arbitrary term-to-term translation given by the
@@ -21,6 +19,7 @@
%-----------------------------------------------------------------------------%
+:- module expand_terms.
:- interface.
:- import_module io.
@@ -33,14 +32,15 @@
main(!IO) :-
io.command_line_arguments(Args, !IO),
- ( Args = [] ->
+ (
+ Args = [],
expand_terms(!IO)
;
+ Args = [_ | _],
expand_terms_file_list(Args, !IO)
).
-:- pred expand_terms_file_list(list(string)::in, io::di, io::uo)
- is det.
+:- pred expand_terms_file_list(list(string)::in, io::di, io::uo) is det.
expand_terms_file_list([], !IO).
expand_terms_file_list([File | Files], !IO) :-
@@ -64,8 +64,7 @@
io.set_exit_status(1, !IO)
).
-:- pred expand_terms_stream(io.input_stream::in, io::di, io::uo)
- is det.
+:- pred expand_terms_stream(io.input_stream::in, io::di, io::uo) is det.
expand_terms_stream(Stream, !IO) :-
io.set_input_stream(Stream, _OldStream, !IO),
@@ -77,8 +76,7 @@
term_io.read_term(Result, !IO),
expand_terms_2(Result, !IO).
-:- pred expand_terms_2(read_term::in, io::di, io::uo)
- is det.
+:- pred expand_terms_2(read_term::in, io::di, io::uo) is det.
expand_terms_2(Result, !IO) :-
(
Index: sort.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/sort.m,v
retrieving revision 1.5
diff -u -r1.5 sort.m
--- sort.m 12 Aug 2005 04:50:37 -0000 1.5
+++ sort.m 21 Mar 2006 00:36:06 -0000
@@ -19,9 +19,17 @@
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
-:- import_module string, list, char, require, std_util.
+
+:- import_module char.
+:- import_module list.
+:- import_module require.
+:- import_module string.
+:- import_module std_util.
+
+%-----------------------------------------------------------------------------%
main(!IO) :-
io.command_line_arguments(Args, !IO),
Index: ultra_sub.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/ultra_sub.m,v
retrieving revision 1.7
diff -u -r1.7 ultra_sub.m
--- ultra_sub.m 12 Aug 2005 04:50:37 -0000 1.7
+++ ultra_sub.m 21 Mar 2006 00:36:40 -0000
@@ -34,6 +34,8 @@
:- pred main(io::di, io::uo) is det.
%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
:- implementation.
:- import_module list, string, char, map, svmap.
@@ -137,7 +139,6 @@
remove_last_2(X, [Y | Ys], [X | Zs], W) :-
remove_last_2(Y, Ys, Zs, W).
-
%------------------------------------------------------------------------------%
:- pred sub(list(char)::in, map(char, list(char))::in, list(char)::out) is det.
Index: c_interface/short_example.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/short_example.m,v
retrieving revision 1.3
diff -u -r1.3 short_example.m
--- c_interface/short_example.m 23 Feb 2005 13:29:00 -0000 1.3
+++ c_interface/short_example.m 21 Mar 2006 00:10:17 -0000
@@ -19,7 +19,9 @@
puts(S::in, Old_IO::di, New_IO::uo),
[promise_pure, will_not_call_mercury],
"
- puts(S); New_IO = Old_IO;
+ puts(S);
+ New_IO = Old_IO;
").
-main(!IO) :- puts("Hello, world\n", !IO).
+main(!IO) :-
+ puts("Hello, world\n", !IO).
Index: c_interface/c_calls_mercury/c_main_int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/c_calls_mercury/c_main_int.m,v
retrieving revision 1.3
diff -u -r1.3 c_main_int.m
--- c_interface/c_calls_mercury/c_main_int.m 24 Mar 1999 03:20:28 -0000 1.3
+++ c_interface/c_calls_mercury/c_main_int.m 20 Mar 2006 23:44:20 -0000
@@ -12,7 +12,7 @@
% Mercury predicate as one that takes an io__state pair. If we didn't do
% this, the Mercury compiler might optimize away calls to it!
-:- pred c_main(io__state::di, io__state::uo) is det.
+:- pred c_main(io::di, io::uo) is det.
:- implementation.
@@ -21,9 +21,14 @@
% Note that any double quotes or backslashes in the C code for
% the `#include' line must be escaped, since the C code is
% given as a Mercury string.
-:- pragma c_header_code("#include \"c_main.h\"").
+:- pragma foreign_decl("C", "#include \"c_main.h\"").
% Define the Mercury predicate c_main to call the C function
% c_main.
-:- pragma c_code(c_main(IO0::di, IO::uo), [may_call_mercury],
- "c_main(); IO = IO0;").
+:- pragma foreign_proc("C",
+ c_main(IO0::di, IO::uo),
+ [may_call_mercury, promise_pure],
+"
+ c_main();
+ IO = IO0;
+").
Index: c_interface/c_calls_mercury/mercury_lib.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/c_calls_mercury/mercury_lib.m,v
retrieving revision 1.4
diff -u -r1.4 mercury_lib.m
--- c_interface/c_calls_mercury/mercury_lib.m 24 Mar 1999 03:20:29 -0000 1.4
+++ c_interface/c_calls_mercury/mercury_lib.m 20 Mar 2006 23:43:14 -0000
@@ -4,24 +4,31 @@
:- module mercury_lib.
:- interface.
-% a Mercury predicate with multiple modes
+ % A Mercury predicate with multiple modes.
+ %
:- pred foo(int).
:- mode foo(in) is semidet.
:- mode foo(out) is multi.
-% a Mercury function with multiple modes
+ % A Mercury function with multiple modes.
+ %
:- func bar(int) = int.
:- mode bar(in) = out is det.
:- mode bar(out) = in is det.
:- mode bar(in) = in is semidet.
-% a semidet (i.e. partial) Mercury function
+ % A semidet (i.e. partial) Mercury function.
:- func baz(int) = int.
:- mode baz(in) = out is semidet.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
:- implementation.
-:- import_module list, std_util, int.
+
+:- import_module int.
+:- import_module list.
+:- import_module std_util.
% well, this is just a silly example...
foo(42).
Index: c_interface/c_calls_mercury/mercury_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/c_calls_mercury/mercury_main.m,v
retrieving revision 1.3
diff -u -r1.3 mercury_main.m
--- c_interface/c_calls_mercury/mercury_main.m 21 Dec 2001 06:22:59 -0000 1.3
+++ c_interface/c_calls_mercury/mercury_main.m 20 Mar 2006 23:40:19 -0000
@@ -4,7 +4,7 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
@@ -18,7 +18,7 @@
:- import_module c_main_int.
% main just invokes c_main
-main -->
- io__write_string("In Mercury main, about to call c_main...\n"),
- c_main,
- io__write_string("Back in Mercury main.\n").
+main(!IO) :-
+ io.write_string("In Mercury main, about to call c_main...\n", !IO),
+ c_main(!IO),
+ io.write_string("Back in Mercury main.\n", !IO).
Index: c_interface/cplusplus_calls_mercury/cpp_main_int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/cplusplus_calls_mercury/cpp_main_int.m,v
retrieving revision 1.2
diff -u -r1.2 cpp_main_int.m
--- c_interface/cplusplus_calls_mercury/cpp_main_int.m 10 Sep 1997 11:00:59 -0000 1.2
+++ c_interface/cplusplus_calls_mercury/cpp_main_int.m 20 Mar 2006 23:45:57 -0000
@@ -4,7 +4,6 @@
% This source file is hereby placed in the public domain. -fjh (the author).
:- module cpp_main_int.
-
:- interface.
:- import_module io.
@@ -12,7 +11,7 @@
% Mercury predicate as one that takes an io__state pair. If we didn't do
% this, the Mercury compiler might optimize away calls to it!
-:- pred cpp_main(io__state::di, io__state::uo) is det.
+:- pred cpp_main(io::di, io::uo) is det.
:- implementation.
@@ -21,11 +20,14 @@
% Note that any double quotes or backslashes in the C code for
% the `#include' line must be escaped, since the C code is
% given as a Mercury string.
-:- pragma c_header_code("#include \"cpp_main.h\"").
+:- pragma foreign_decl("C", "#include \"cpp_main.h\"").
% Define the Mercury predicate cpp_main to call the C++ function
% cpp_main.
-:- pragma c_code(cpp_main(IO0::di, IO::uo), may_call_mercury, "
+:- pragma foreign_proc("C",
+ cpp_main(IO0::di, IO::uo),
+ [may_call_mercury, promise_pure],
+"
cpp_main();
IO = IO0;
").
Index: c_interface/cplusplus_calls_mercury/mercury_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/cplusplus_calls_mercury/mercury_main.m,v
retrieving revision 1.3
diff -u -r1.3 mercury_main.m
--- c_interface/cplusplus_calls_mercury/mercury_main.m 21 Dec 2001 06:23:01 -0000 1.3
+++ c_interface/cplusplus_calls_mercury/mercury_main.m 21 Mar 2006 00:09:52 -0000
@@ -4,7 +4,7 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
@@ -13,12 +13,12 @@
% mercury_lib in the executable.
:- import_module mercury_lib.
-% import the module which defines the Mercury interface to the
+% Import the module which defines the Mercury interface to the
% C++ function cpp_main().
:- import_module cpp_main_int.
% main just invokes cpp_main
-main -->
- io__write_string("In Mercury main, about to call cpp_main...\n"),
- cpp_main,
- io__write_string("Back in Mercury main.\n").
+main(!IO) :-
+ io.write_string("In Mercury main, about to call cpp_main...\n", !IO),
+ cpp_main(!IO),
+ io.write_string("Back in Mercury main.\n", !IO).
Index: c_interface/mercury_calls_c/c_main_int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_c/c_main_int.m,v
retrieving revision 1.2
diff -u -r1.2 c_main_int.m
--- c_interface/mercury_calls_c/c_main_int.m 10 Sep 1997 11:01:02 -0000 1.2
+++ c_interface/mercury_calls_c/c_main_int.m 20 Mar 2006 23:38:33 -0000
@@ -4,7 +4,6 @@
% This source file is hereby placed in the public domain. -fjh (the author).
:- module c_main_int.
-
:- interface.
:- import_module io.
@@ -12,7 +11,7 @@
% Mercury predicate as one that takes an io__state pair. If we didn't do
% this, the Mercury compiler might optimize away calls to it!
-:- pred c_main(io__state::di, io__state::uo) is det.
+:- pred c_main(io::di, io::uo) is det.
:- implementation.
@@ -21,8 +20,13 @@
% Note that any double quotes or backslashes in the C code for
% the `#include' line must be escaped, since the C code is
% given as a Mercury string.
-:- pragma c_header_code("#include \"c_main.h\"").
+:- pragma foreign_decl("C", "#include \"c_main.h\"").
% Define the Mercury predicate c_main to call the C function
% c_main.
-:- pragma c_code(c_main(IO0::di, IO::uo), "c_main(); IO = IO0;").
+:- pragma foreign_proc("C",
+ c_main(IO0::di, IO::uo),
+ [promise_pure, will_not_call_mercury],
+"
+ c_main(); IO = IO0;
+").
Index: c_interface/mercury_calls_c/mercury_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_c/mercury_main.m,v
retrieving revision 1.2
diff -u -r1.2 mercury_main.m
--- c_interface/mercury_calls_c/mercury_main.m 10 Sep 1997 11:01:03 -0000 1.2
+++ c_interface/mercury_calls_c/mercury_main.m 20 Mar 2006 23:36:20 -0000
@@ -4,7 +4,7 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
@@ -13,7 +13,7 @@
:- import_module c_main_int.
% main just invokes c_main
-main -->
- io__write_string("In Mercury main, about to call c_main...\n"),
- c_main,
- io__write_string("Back in Mercury main.\n").
+main(!IO) :-
+ io.write_string("In Mercury main, about to call c_main...\n", !IO),
+ c_main(!IO),
+ io.write_string("Back in Mercury main.\n", !IO).
Index: c_interface/mercury_calls_cplusplus/cpp_main_int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_cplusplus/cpp_main_int.m,v
retrieving revision 1.2
diff -u -r1.2 cpp_main_int.m
--- c_interface/mercury_calls_cplusplus/cpp_main_int.m 10 Sep 1997 11:01:05 -0000 1.2
+++ c_interface/mercury_calls_cplusplus/cpp_main_int.m 20 Mar 2006 23:54:58 -0000
@@ -9,10 +9,10 @@
:- import_module io.
% Since the cpp_main() function has side effects, we declare the corresponding
-% Mercury predicate as one that takes an io__state pair. If we didn't do
+% Mercury predicate as one that takes an io.state pair. If we didn't do
% this, the Mercury compiler might optimize away calls to it!
-:- pred cpp_main(io__state::di, io__state::uo) is det.
+:- pred cpp_main(io::di, io::uo) is det.
:- implementation.
@@ -21,8 +21,13 @@
% Note that any double quotes or backslashes in the C code for
% the `#include' line must be escaped, since the C code is
% given as a Mercury string.
-:- pragma c_header_code("#include \"cpp_main.h\"").
+:- pragma foreign_decl("C", "#include \"cpp_main.h\"").
% Define the Mercury predicate cpp_main to call the C++ function
% cpp_main.
-:- pragma c_code(cpp_main(IO0::di, IO::uo), "cpp_main(); IO = IO0;").
+:- pragma foreign_proc("C",
+ cpp_main(IO0::di, IO::uo),
+ [will_not_call_mercury, promise_pure],
+"
+ cpp_main(); IO = IO0;
+").
Index: c_interface/mercury_calls_cplusplus/mercury_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_cplusplus/mercury_main.m,v
retrieving revision 1.2
diff -u -r1.2 mercury_main.m
--- c_interface/mercury_calls_cplusplus/mercury_main.m 10 Sep 1997 11:01:06 -0000 1.2
+++ c_interface/mercury_calls_cplusplus/mercury_main.m 20 Mar 2006 23:55:35 -0000
@@ -4,16 +4,16 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
-% import the module which defines the Mercury interface to the
+% Import the module which defines the Mercury interface to the
% C++ function cpp_main().
:- import_module cpp_main_int.
% main just invokes cpp_main
-main -->
- io__write_string("In Mercury main, about to call cpp_main...\n"),
- cpp_main,
- io__write_string("Back in Mercury main.\n").
+main(!IO) :-
+ io.write_string("In Mercury main, about to call cpp_main...\n", !IO),
+ cpp_main(!IO),
+ io.write_string("Back in Mercury main.\n", !IO).
Index: c_interface/mercury_calls_fortran/fortran_main_int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_fortran/fortran_main_int.m,v
retrieving revision 1.1
diff -u -r1.1 fortran_main_int.m
--- c_interface/mercury_calls_fortran/fortran_main_int.m 19 May 1998 10:13:58 -0000 1.1
+++ c_interface/mercury_calls_fortran/fortran_main_int.m 21 Mar 2006 00:11:44 -0000
@@ -13,7 +13,7 @@
% corresponding Mercury predicate as one that takes an io__state pair.
% If we didn't do this, the Mercury compiler might optimize away calls to it!
-:- pred fortran_main(io__state::di, io__state::uo) is det.
+:- pred fortran_main(io::di, io::uo) is det.
:- implementation.
Index: c_interface/mercury_calls_fortran/mercury_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/mercury_calls_fortran/mercury_main.m,v
retrieving revision 1.1
diff -u -r1.1 mercury_main.m
--- c_interface/mercury_calls_fortran/mercury_main.m 19 May 1998 10:13:59 -0000 1.1
+++ c_interface/mercury_calls_fortran/mercury_main.m 21 Mar 2006 00:11:21 -0000
@@ -4,16 +4,17 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
-% import the module which defines the Mercury interface to the
+% Import the module which defines the Mercury interface to the
% Fortran procedure `FORTRAN_MAIN'.
:- import_module fortran_main_int.
% main just invokes fortran_main
-main -->
- io__write_string("In Mercury main, about to call fortran_main...\n"),
- fortran_main,
- io__write_string("Back in Mercury main.\n").
+main(!IO) :-
+ io.write_string("In Mercury main, about to call fortran_main...\n",
+ !IO),
+ fortran_main(!IO),
+ io.write_string("Back in Mercury main.\n", !IO).
Index: c_interface/simpler_c_calls_mercury/mercury_lib.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/simpler_c_calls_mercury/mercury_lib.m,v
retrieving revision 1.3
diff -u -r1.3 mercury_lib.m
--- c_interface/simpler_c_calls_mercury/mercury_lib.m 10 Sep 1997 11:01:08 -0000 1.3
+++ c_interface/simpler_c_calls_mercury/mercury_lib.m 21 Mar 2006 00:14:52 -0000
@@ -5,32 +5,41 @@
:- interface.
:- import_module io.
-% To avoid link errors, there still has to be a main/2 defined somewhere
-% in the program; it won't be used, unless the C program calls
-% mercury_call_main(), which will call main/2.
-:- pred main(io__state::di, io__state::uo) is det.
+ % To avoid link errors, there still has to be a main/2 defined
+ % somewhere in the program; it won't be used, unless the C program
+ % calls mercury_call_main(), which will call main/2.
+ %
+:- pred main(io::di, io::uo) is det.
-% a Mercury predicate with multiple modes
+ % A Mercury predicate with multiple modes.
+ %
:- pred foo(int).
:- mode foo(in) is semidet.
:- mode foo(out) is multi.
-% a Mercury function with multiple modes
+ % A Mercury function with multiple modes.
+ %
:- func bar(int) = int.
:- mode bar(in) = out is det.
:- mode bar(out) = in is det.
:- mode bar(in) = in is semidet.
-% a semidet (i.e. partial) Mercury function
+ % A semidet (i.e. partial) Mercury function.
+ %
:- func baz(int) = int.
:- mode baz(in) = out is semidet.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
:- implementation.
-:- import_module std_util, int, list.
+
+:- import_module int.
+:- import_module list.
+:- import_module std_util.
% for this example, main/2 isn't useful
-main --> [].
+main(!IO).
% well, this is just a silly example...
foo(42).
Index: c_interface/simpler_cplusplus_calls_mercury/mercury_lib.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/c_interface/simpler_cplusplus_calls_mercury/mercury_lib.m,v
retrieving revision 1.3
diff -u -r1.3 mercury_lib.m
--- c_interface/simpler_cplusplus_calls_mercury/mercury_lib.m 10 Sep 1997 11:01:10 -0000 1.3
+++ c_interface/simpler_cplusplus_calls_mercury/mercury_lib.m 21 Mar 2006 00:17:51 -0000
@@ -5,32 +5,41 @@
:- interface.
:- import_module io.
-% To avoid link errors, there still has to be a main/2 defined somewhere
-% in the program; it won't be used, unless the C program calls
-% mercury_call_main(), which will call main/2.
-:- pred main(io__state::di, io__state::uo) is det.
+ % To avoid link errors, there still has to be a main/2 defined
+ % somewhere in the program; it won't be used, unless the C program
+ % calls mercury_call_main(), which will call main/2.
+ %
+:- pred main(io::di, io::uo) is det.
-% a Mercury predicate with multiple modes
+ % A Mercury predicate with multiple modes.
+ %
:- pred foo(int).
:- mode foo(in) is semidet.
:- mode foo(out) is multi.
-% a Mercury function with multiple modes
+ % A Mercury function with multiple modes.
+ %
:- func bar(int) = int.
:- mode bar(in) = out is det.
:- mode bar(out) = in is det.
:- mode bar(in) = in is semidet.
-% a semidet (i.e. partial) Mercury function
+ % A semidet (i.e. partial) Mercury function.
+ %
:- func baz(int) = int.
:- mode baz(in) = out is semidet.
%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
:- implementation.
-:- import_module std_util, int, list.
+
+:- import_module int.
+:- import_module list.
+:- import_module std_util.
% for this example, main/2 isn't useful
-main --> [].
+main(!IO).
% well, this is just a silly example...
foo(42).
Index: solutions/all_solutions.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/solutions/all_solutions.m,v
retrieving revision 1.1
diff -u -r1.1 all_solutions.m
--- solutions/all_solutions.m 20 Oct 1999 03:14:30 -0000 1.1
+++ solutions/all_solutions.m 21 Mar 2006 00:31:56 -0000
@@ -8,16 +8,16 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is det.
+:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module std_util.
-main -->
- { solutions(hello, List) },
- io__write_strings(List).
+main(!IO) :-
+ solutions(hello, List),
+ io.write_strings(List, !IO).
-:- pred hello(string::out) is multidet.
+:- pred hello(string::out) is multi.
hello("Hello, world\n").
hello("Hello again, world\n").
Index: solutions/n_solutions.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/solutions/n_solutions.m,v
retrieving revision 1.1
diff -u -r1.1 n_solutions.m
--- solutions/n_solutions.m 26 Jul 2004 00:51:24 -0000 1.1
+++ solutions/n_solutions.m 21 Mar 2006 00:27:17 -0000
@@ -14,10 +14,12 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is cc_multi.
+:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
-:- import_module std_util, bool, int.
+:- import_module bool.
+:- import_module int.
+:- import_module std_util.
main(!IO) :-
N = 2,
Index: solutions/one_solution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/solutions/one_solution.m,v
retrieving revision 1.1
diff -u -r1.1 one_solution.m
--- solutions/one_solution.m 20 Oct 1999 03:14:30 -0000 1.1
+++ solutions/one_solution.m 21 Mar 2006 00:27:53 -0000
@@ -19,9 +19,9 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is cc_multi.
+:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
-main --> io__write_string("Hello, world\n").
-main --> io__write_string("Goodbye, world\n").
+main(!IO) :- io.write_string("Hello, world\n", !IO).
+main(!IO) :- io.write_string("Goodbye, world\n", !IO).
Index: solutions/some_solutions.m
===================================================================
RCS file: /home/mercury1/repository/mercury/samples/solutions/some_solutions.m,v
retrieving revision 1.2
diff -u -r1.2 some_solutions.m
--- solutions/some_solutions.m 13 Dec 1999 16:52:10 -0000 1.2
+++ solutions/some_solutions.m 21 Mar 2006 00:30:23 -0000
@@ -17,14 +17,17 @@
:- interface.
:- import_module io.
-:- pred main(io__state::di, io__state::uo) is cc_multi.
+:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
-:- import_module std_util, char, bool, list.
-
-main -->
- do_while(hello, get_next),
- io__write_string("No (more) solutions\n").
+:- import_module bool.
+:- import_module char.
+:- import_module list.
+:- import_module std_util.
+
+main(!IO) :-
+ do_while(hello, get_next, !IO),
+ io.write_string("No (more) solutions\n", !IO).
:- pred hello(string::out) is multi.
@@ -32,18 +35,18 @@
hello("Good day, world\n").
hello("Greetings, world\n").
-:- pred get_next(string::in, bool::out, io__state::di, io__state::uo) is det.
+:- pred get_next(string::in, bool::out, io::di, io::uo) is det.
-get_next(String, More) -->
+get_next(String, More, !IO) :-
% print the first answer
- io__write_string(String),
+ io.write_string(String, !IO),
% see if the user wants more answers
- io__write_string("More? "),
- io__read_line(Line),
- { if Line = ok([FirstChar|_]),
- char__to_upper(FirstChar, 'Y')
+ io.write_string("More? ", !IO),
+ io.read_line(Line, !IO),
+ ( if Line = ok([FirstChar|_]),
+ char.to_upper(FirstChar, 'Y')
then More = yes
- else More = no
- }.
+ else More = no
+ ).
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list