Skip to content

Commit

Permalink
Fix samples/rot13_concise + libxml compilation error
Browse files Browse the repository at this point in the history
boehm_gc/.gitignore:
    Ignore .obj files

extras/xml/xml.dtd.m:
extras/xml/xml.parse.m:
    Change the name of functor ('1') in the multiplicity/0 type
    to one. The former name does not (yet) work with the C# grade.

samples/.gitignore:
    Ignore library output and sample executables.

samples/c_interface/standalone_c/.gitignore:
    Ignore mercury_lib_int output files.

samples/c_interface/standalone_c/Makefile:
    chmod 0644.

samples/c_interface/.gitignore:
    Ignore object files and executables.

samples/java_interface/.gitignore:
    Ignore Java class files and executables.

samples/lazy_list/.gitignore:
samples/muz/.gitignore:
samples/rot13/.gitignore:
    Ignore executables.

samples/rot13/rot13_concise.m:
    Update call to index_det to use string.det_index.
    Added comments to clarify type inference.

samples/solutions/.gitignore:
    Ignore executables.

samples/solutions/all_solutions.m:
samples/solutions/n_solutions.m:
samples/solutions/one_solution.m:
samples/solutions/some_solutions.m:
    chmod 0644.

samples/solver_types/.gitignore:
    Ignore executables.

samples/solver_types/sudoku.m:
    Output the solution in a 3x3 grid.
  • Loading branch information
sebgod authored and opturion-jfischer committed Mar 11, 2014
1 parent a03ba31 commit 59ce153
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extras/xml/xml.dtd.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
---> mixed(list(name)).

:- type multiplicity
---> ('1')
---> one
; ('*')
; ('+')
; ('?')
Expand Down
2 changes: 1 addition & 1 deletion extras/xml/xml.parse.m
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ multiplicity then (pred(Mult::in, pdi, puo) is det -->
:- 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) ('?' | '*' | '+')?

Expand Down
23 changes: 23 additions & 0 deletions samples/.gitignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions samples/c_interface/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
c_main.o*
c_main
cpp_main.o*
cpp_main
mercury_main
short_example
1 change: 1 addition & 0 deletions samples/c_interface/standalone_c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mercury_lib_int.[cho]
2 changes: 2 additions & 0 deletions samples/java_interface/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mercury_main
my_package
1 change: 1 addition & 0 deletions samples/lazy_list/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lazy_list_test
1 change: 1 addition & 0 deletions samples/muz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
muz
5 changes: 5 additions & 0 deletions samples/rot13/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rot13_concise
rot13_juergen
rot13_gustavo
rot13_ralph
rot13_verbose
9 changes: 8 additions & 1 deletion samples/rot13/rot13_concise.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -->
Expand Down
4 changes: 4 additions & 0 deletions samples/solutions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all_solutions
n_solutions
one_solution
some_solutions
Empty file modified samples/solutions/n_solutions.m
100755 → 100644
Empty file.
Empty file modified samples/solutions/one_solution.m
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions samples/solver_types/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudoku
test_eqneq
20 changes: 14 additions & 6 deletions samples/solver_types/sudoku.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
)
Expand Down Expand Up @@ -169,19 +169,27 @@

% 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)
).

%-----------------------------------------------------------------------------%
Expand Down

0 comments on commit 59ce153

Please sign in to comment.