mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-10 03:13:46 +00:00
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.
75 lines
1.2 KiB
Mathematica
75 lines
1.2 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Test the tracking of a subterm through an explicit supertree.
|
|
|
|
:- module explicit_subtree.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module exception.
|
|
:- import_module int.
|
|
|
|
main(!IO) :-
|
|
p1(10, Q),
|
|
write_int(Q, !IO),
|
|
nl(!IO).
|
|
|
|
:- pred p1(int::in, int::out) is det.
|
|
:- pred p2(int::in, int::out) is det.
|
|
:- pred p3(int::in, int::out) is det.
|
|
|
|
p1(X, Y) :- p2(X, Y).
|
|
p2(X, Y) :- p3(X, Y).
|
|
p3(X, Y) :- calc(X, Y).
|
|
|
|
:- pred calc(int::in, int::out) is det.
|
|
|
|
calc(X, Y) :-
|
|
(
|
|
X > 0
|
|
->
|
|
a(Z)
|
|
;
|
|
b(Z)
|
|
),
|
|
divide2(X, Z, Y).
|
|
|
|
:- pred divide2(int::in, int::in, int::out) is det.
|
|
|
|
divide2(N, D, Q) :-
|
|
(
|
|
D = 0
|
|
->
|
|
throw("zero denominator")
|
|
;
|
|
Q = N // D
|
|
).
|
|
|
|
:- pred b(int::out) is det.
|
|
|
|
b(-1).
|
|
|
|
:- pred a(int::out) is det.
|
|
|
|
a(X + Y - 100) :-
|
|
q(49, 0, X), q(51, 0, Y).
|
|
|
|
:- pred q(int::in, int::in, int::out) is det.
|
|
|
|
q(A, B, C) :-
|
|
(
|
|
A =< 0
|
|
->
|
|
B = C
|
|
;
|
|
q(A-1, B+1, C)
|
|
).
|