diff --git a/extras/xml/xml.dtd.m b/extras/xml/xml.dtd.m index 3719b1307..2d502089b 100644 --- a/extras/xml/xml.dtd.m +++ b/extras/xml/xml.dtd.m @@ -57,7 +57,7 @@ ---> mixed(list(name)). :- type multiplicity - ---> ('1') + ---> one ; ('*') ; ('+') ; ('?') diff --git a/extras/xml/xml.parse.m b/extras/xml/xml.parse.m index cbf74c31c..bd6f52850 100644 --- a/extras/xml/xml.parse.m +++ b/extras/xml/xml.parse.m @@ -1746,7 +1746,7 @@ children --> :- mode multiplicity(in, out) is det. multiplicity --> - opt(lit1(('?'), ('?')) or lit1(('*'), ('*')) or lit1(('+'), ('+')), '1'). + opt(lit1(('?'), ('?')) or lit1(('*'), ('*')) or lit1(('+'), ('+')), one). % [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? diff --git a/samples/.gitignore b/samples/.gitignore new file mode 100644 index 000000000..08aa60053 --- /dev/null +++ b/samples/.gitignore @@ -0,0 +1,23 @@ +Mercury +Mercury/** +*.mh +*.init +*.err +*.jar +*.dll +*.exe +*.bat +lib*.dylib +lib*.dll +lib*.so +lib*.a +hello +calculator +calculator2 +cat +e +eliza +expand_terms +interpreter +sort +ultra_sub diff --git a/samples/c_interface/.gitignore b/samples/c_interface/.gitignore new file mode 100644 index 000000000..511021cd9 --- /dev/null +++ b/samples/c_interface/.gitignore @@ -0,0 +1,6 @@ +c_main.o* +c_main +cpp_main.o* +cpp_main +mercury_main +short_example diff --git a/samples/c_interface/standalone_c/.gitignore b/samples/c_interface/standalone_c/.gitignore new file mode 100644 index 000000000..532bd66e1 --- /dev/null +++ b/samples/c_interface/standalone_c/.gitignore @@ -0,0 +1 @@ +mercury_lib_int.[cho] diff --git a/samples/java_interface/.gitignore b/samples/java_interface/.gitignore new file mode 100644 index 000000000..111dcd91c --- /dev/null +++ b/samples/java_interface/.gitignore @@ -0,0 +1,2 @@ +mercury_main +my_package diff --git a/samples/lazy_list/.gitignore b/samples/lazy_list/.gitignore new file mode 100644 index 000000000..5a2e90117 --- /dev/null +++ b/samples/lazy_list/.gitignore @@ -0,0 +1 @@ +lazy_list_test diff --git a/samples/muz/.gitignore b/samples/muz/.gitignore new file mode 100644 index 000000000..0effa1ad0 --- /dev/null +++ b/samples/muz/.gitignore @@ -0,0 +1 @@ +muz diff --git a/samples/rot13/.gitignore b/samples/rot13/.gitignore new file mode 100644 index 000000000..ed3973dc9 --- /dev/null +++ b/samples/rot13/.gitignore @@ -0,0 +1,5 @@ +rot13_concise +rot13_juergen +rot13_gustavo +rot13_ralph +rot13_verbose diff --git a/samples/rot13/rot13_concise.m b/samples/rot13/rot13_concise.m index 02217b788..f0d234df6 100644 --- a/samples/rot13/rot13_concise.m +++ b/samples/rot13/rot13_concise.m @@ -10,6 +10,8 @@ % This version is more concise (but less efficient) than its companion, % rot13_verbose. % +% Compile with: mmc --make --infer-all +% % Key features: % - is independent of character set (e.g. ASCII, EBCDIC) % - has proper error handling @@ -27,18 +29,23 @@ :- import_module char, int, string. % The length of `alphabet' should be a multiple of `cycle'. +% Inferred declaration: func alphabet = string. alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". + +% Inferred declaration: func cycle = int. cycle = 26. +% Inferred declaration: func rot_n(int, char) = char. rot_n(N, Char) = RotChar :- char_to_string(Char, CharString), ( if sub_string_search(alphabet, CharString, Index) then NewIndex = (Index + N) mod cycle + cycle * (Index // cycle), - index_det(alphabet, NewIndex, RotChar) + string.det_index(alphabet, NewIndex, RotChar) else RotChar = Char ). +% Inferred declaration: func rot13(char) = char. rot13(Char) = rot_n(13, Char). main --> diff --git a/samples/solutions/.gitignore b/samples/solutions/.gitignore new file mode 100644 index 000000000..c13918244 --- /dev/null +++ b/samples/solutions/.gitignore @@ -0,0 +1,4 @@ +all_solutions +n_solutions +one_solution +some_solutions diff --git a/samples/solutions/n_solutions.m b/samples/solutions/n_solutions.m old mode 100755 new mode 100644 diff --git a/samples/solutions/one_solution.m b/samples/solutions/one_solution.m old mode 100755 new mode 100644 diff --git a/samples/solver_types/.gitignore b/samples/solver_types/.gitignore new file mode 100644 index 000000000..b2f251539 --- /dev/null +++ b/samples/solver_types/.gitignore @@ -0,0 +1,2 @@ +sudoku +test_eqneq diff --git a/samples/solver_types/sudoku.m b/samples/solver_types/sudoku.m index 2f34eac7c..14b2778e1 100644 --- a/samples/solver_types/sudoku.m +++ b/samples/solver_types/sudoku.m @@ -40,7 +40,7 @@ main(!IO) :- ReadResult = ok(StartString), Start = string.words(StartString), ( if solve_sudoku(Start, Solution) then - write_solution(9, Solution, !IO) + write_solution(9, 1, Solution, !IO) else io.write_string("No solution.\n", !IO) ) @@ -169,19 +169,27 @@ label_board([EqNeq | EqNeqs], [X | Xs]) :- % Pretty-print a solution. % -:- pred write_solution(int::in, list(int)::in, io::di, io::uo) is det. +:- pred write_solution(int::in, int::in, list(int)::in, io::di, io::uo) is det. -write_solution(_, [], !IO) :- +write_solution(_, _, [], !IO) :- io.nl(!IO). -write_solution(N, [X | Xs], !IO) :- +write_solution(N, R, [X | Xs], !IO) :- ( if N = 0 then io.nl(!IO), - write_solution(9, [X | Xs], !IO) + ( if (R mod 3) = 0 + then io.nl(!IO) + else true + ), + write_solution(9, R + 1, [X | Xs], !IO) else io.write_int(X, !IO), io.write_char(' ', !IO), - write_solution(N - 1, Xs, !IO) + ( if (N mod 3) = 1 + then io.write_char(' ', !IO) + else true + ), + write_solution(N - 1, R + 1, Xs, !IO) ). %-----------------------------------------------------------------------------%