Files
mercury/tests/invalid/syntax_error_event.m
Zoltan Somogyi fdd141bf77 Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the tests
    that check compiler error messages, expect the new line numbers.

browser/cterm.m:
browser/tree234_cc.m:
    Import only one module per line.

tests/hard_coded/boyer.m:
    Fix something I missed.
2015-02-16 12:32:18 +11:00

105 lines
2.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module syntax_error_event.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module list.
:- import_module int.
:- type listint == list(int).
main(!IO) :-
data(Data),
( queen(Data, Out) ->
print_list(Out, !IO)
;
io.write_string("No solution\n", !IO)
).
:- pred data(list(int)::out) is det.
data([1, 2, 3, 4, 5]).
:- pred queen(list(int)::in, list(int)::out) is nondet.
queen(Data, Out) :-
qperm(Data, Out),
event safe_test(Data, Out),
safe(Out).
:- pred qperm(list(T)::in, list(T)::out) is nondet.
qperm([], []).
qperm(L, K) :-
L = [_ | _],
qdelete(U, L, Z),
K = [U | V],
qperm(Z, V).
:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet.
qdelete(A, [A | L], L).
qdelete(X, [A | Z], [A | R]) :-
qdelete(X, Z, R).
:- pred safe(list(int)::in) is semidet.
safe([]).
safe([N | L]) :-
nodiag(N, 1, L),
event nodiag_succeed(N, L),
safe(L).
:- pred nodiag(int::in, int::in, list(int)::in) is semidet.
nodiag(_, _, []).
nodiag(B, D, [N | L]) :-
NmB = N - B,
BmN = B - N,
( D = NmB ->
event nodiag_fail("N - B", B, N, [N | L]),
fail
; D = BmN ->
event nodiag_fail("B - N", B, N, [N | L]),
fail
;
true
),
D1 = D + 1,
nodiag(B, D1, L).
:- pred print_list(list(int)::in, io::di, io::uo) is det.
print_list(Xs, !IO) :-
(
Xs = [],
io.write_string("[]\n", !IO)
;
Xs = [_ | _],
io.write_string("[", !IO),
print_list_2(Xs, !IO),
io.write_string("]\n", !IO)
).
:- pred print_list_2(list(int)::in, io::di, io::uo) is det.
print_list_2([], !IO).
print_list_2([X | Xs], !IO) :-
io.write_int(X, !IO),
(
Xs = []
;
Xs = [_ | _],
io__write_string(", ", !IO),
print_list_2(Xs, !IO)
).