[m-rev.] for review: Fixing samples/rot13_concise + libxml compile error
Sebastian Godelet
sebastian.godelet+github at gmail.com
Sat Mar 1 03:54:16 AEDT 2014
Hello,
for a quick review, my last problems I had with going through all the
samples and extras, except the wix compiler, that one I didn't figure out
yet.
branch: master
boehm_gc/.gitignore b/boehm_gc/.gitignore:
ignoring Windows 'cl' .obj files
extras/xml/xml.dtd.m b/extras/xml/xml.dtd.m:
extras/xml/xml.parse.m b/extras/xml/xml.parse.m:
Changing multiplicity ('1') -> one, such that it compiles (and works)
in the C# grade.
samples/rot13/rot13_concise.m:
added missing func and pred declarations
changed string index_det -> string.det_index.
samples/solver_types/sudoku.m:
The solution grid is now in a 3x3 block format,
for that the row number is accumulated in write_solution predicate.
Cheers,
Sebastian.
diff --git a/boehm_gc/.gitignore b/boehm_gc/.gitignore
index 1ccf936..99fe1e6 100644
--- a/boehm_gc/.gitignore
+++ b/boehm_gc/.gitignore
@@ -10,6 +10,7 @@ mercury_boehm_gc_conf.h
gc.lib
libgc.lib
*.a
+*.obj
*.exe
*.ilk
*.o
diff --git a/extras/xml/xml.dtd.m b/extras/xml/xml.dtd.m
index 3719b13..6906849 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 cbf74c3..bd6f528 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/rot13/rot13_concise.m b/samples/rot13/rot13_concise.m
index 02217b7..5c063a3 100644
--- a/samples/rot13/rot13_concise.m
+++ b/samples/rot13/rot13_concise.m
@@ -27,18 +27,23 @@
:- import_module char, int, string.
% The length of `alphabet' should be a multiple of `cycle'.
+:- func alphabet = string.
+
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".
+:- func cycle = int.
cycle = 26.
+:- 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
).
+:- func rot13(char) = char.
rot13(Char) = rot_n(13, Char).
main -->
diff --git a/samples/solver_types/sudoku.m b/samples/solver_types/sudoku.m
index 2f34eac..14b2778 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)
).
%-----------------------------------------------------------------------------%
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20140228/b9bdca3b/attachment.html>
More information about the reviews
mailing list