Files
mercury/tests/debugger/shallow.m
Zoltan Somogyi 33eb3028f5 Clean up the tests in half the test directories.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
    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 debugger tests,
    specify the new line numbers in .inp files and expect them in .exp files.
2015-02-14 20:14:03 +11:00

83 lines
1.6 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module shallow.
:- interface.
:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is cc_multi.
:- implementation.
:- import_module list.
:- import_module int.
:- import_module shallow2.
main -->
( { data(Data), queen(Data, Out) } ->
print_list(Out)
;
io__write_string("No solution\n")
).
:- pred data(list(int)).
:- mode data(out) is det.
:- pred queen(list(int), list(int)).
:- mode queen(in, out) is nondet.
:- pred qperm(list(T), list(T)).
:- mode qperm(in, out) is nondet.
:- pred qdelete(T, list(T), list(T)).
:- mode qdelete(out, in, out) is nondet.
data([1, 2, 3, 4, 5]).
queen(Data, Out) :-
qperm(Data, Out),
safe(Out).
qperm([], []).
qperm([X | Y], K) :-
qdelete(U, [X | Y], Z),
K = [U | V],
qperm(Z, V).
qdelete(A, [A | L], L).
qdelete(X, [A | Z], [A | R]) :-
qdelete(X, Z, R).
:- pred print_list(list(int), io__state, io__state).
:- mode print_list(in, di, uo) is det.
print_list(Xs) -->
(
{ Xs = [] }
->
io__write_string("[]\n")
;
io__write_string("["),
print_list_2(Xs),
io__write_string("]\n")
).
:- pred print_list_2(list(int), io__state, io__state).
:- mode print_list_2(in, di, uo) is det.
print_list_2([]) --> [].
print_list_2([X | Xs]) -->
io__write_int(X),
(
{ Xs = [] }
->
[]
;
io__write_string(", "),
print_list_2(Xs)
).