mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 04:13:46 +00:00
Estimated hours taken: 3
Handle ambiguous procedure specifications in the debugger's "break" command
more usefully.
trace/mercury_trace_tables.[ch]:
Add a function for returning all the procedures that match a
specification.
trace/mercury_trace_internal.c:
Use this function to present the user all the matches for the procedure
specification if their specification matches more than one procedure,
and let them choose whether they want to put a breakpoint on them all,
and if not, which one to put the breakpoint on.
doc/user_guide.texi:
Document the new functionality.
tests/debugger/breakpoints.{m,in,exp}:
Introduce a function named "data" to go with the predicate, and check
that the "break" command handles the ambiguity properly.
107 lines
1.6 KiB
Mathematica
107 lines
1.6 KiB
Mathematica
:- module breakpoints.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state, io__state).
|
|
:- mode main(di, uo) is cc_multi.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, int.
|
|
|
|
main -->
|
|
( { queen(data, Out) } ->
|
|
print_list(Out)
|
|
;
|
|
io__write_string("No solution\n")
|
|
).
|
|
|
|
:- func data = list(int).
|
|
|
|
:- 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.
|
|
|
|
:- pred safe(list(int)).
|
|
:- mode safe(in) is semidet.
|
|
|
|
:- pred nodiag(int, int, list(int)).
|
|
:- mode nodiag(in, in, in) is semidet.
|
|
|
|
data = D :-
|
|
data(D).
|
|
|
|
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).
|
|
|
|
safe([]).
|
|
safe([N|L]) :-
|
|
nodiag(N, 1, L),
|
|
safe(L).
|
|
|
|
nodiag(_, _, []).
|
|
nodiag(B, D, [N|L]) :-
|
|
NmB is N - B,
|
|
BmN is B - N,
|
|
( D = NmB ->
|
|
fail
|
|
; D = BmN ->
|
|
fail
|
|
;
|
|
true
|
|
),
|
|
D1 is D + 1,
|
|
nodiag(B, D1, L).
|
|
|
|
:- 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)
|
|
).
|