mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 10:53:40 +00:00
This first step deals with the consequences of such removal.
The removal itself will happen in stage 2. That step will
add "is" to the prolog module in the library.
compiler/add_pred.m:
Prepare for "is" being in the prolog module.
compiler/options.m:
Add a way to test whether the change to add_pred.m is in the
installed compiler.
tests/accumulator/base.m:
tests/accumulator/call_in_base.m:
tests/accumulator/chain.m:
tests/accumulator/commutative.m:
tests/accumulator/construct_test.m:
tests/accumulator/dcg.m:
tests/accumulator/deconstruct_test.m:
tests/accumulator/disj.m:
tests/accumulator/func.m:
tests/accumulator/heuristic.m:
tests/accumulator/highorder.m:
tests/accumulator/identity.m:
tests/accumulator/inter.m:
tests/accumulator/nonrec.m:
tests/accumulator/out_to_in.m:
tests/accumulator/qsort.m:
tests/accumulator/simple.m:
tests/accumulator/split.m:
tests/accumulator/swap.m:
tests/benchmarks/cqueens.m:
tests/benchmarks/crypt.m:
tests/benchmarks/deriv.m:
tests/benchmarks/deriv2.m:
tests/benchmarks/nrev.m:
tests/benchmarks/poly.m:
tests/benchmarks/primes.m:
tests/benchmarks/qsort.m:
tests/benchmarks/query.m:
tests/benchmarks/tak.m:
tests/debugger/interactive.m:
tests/declarative_debugger/Mercury.options:
tests/declarative_debugger/io_read_bug.m:
tests/declarative_debugger/queens.exp:
tests/declarative_debugger/queens.m:
tests/dppd/imperative_solve_impl.m:
tests/dppd/map_impl.m:
tests/dppd/max_length_impl.m:
tests/dppd/sum.m:
tests/dppd/upto_sum_impl.m:
tests/par_conj/dep_par_21.m:
tests/tabling/seq.m:
tests/term/dds3_14.m:
tests/term/mmatrix.m:
tests/term/money.m:
tests/term/occur.m:
tests/term/pl4_5_2.m:
tests/term/queens.m:
tests/typeclasses/inference_test.m:
tests/typeclasses/inference_test_2.m:
tests/valid/lazy_list.m:
tests/warnings/duplicate_const.m:
Replace calls to "is" with unifications. In many places,
bring programming style up to date.
119 lines
2.8 KiB
Mathematica
119 lines
2.8 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% query
|
|
%
|
|
% David H. D. Warren
|
|
%
|
|
% query population and area database to find countries of
|
|
% approximately equal population density.
|
|
|
|
:- module query.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module prolog.
|
|
|
|
:- type quad
|
|
---> quad(string, int, string, int).
|
|
|
|
main(!IO) :-
|
|
( if query(Out) then
|
|
Out = quad(C1, D1, C2, D2),
|
|
io.write_string(C1, !IO),
|
|
io.write_string(" has density ", !IO),
|
|
io.write_int(D1, !IO),
|
|
io.write_string(" while ", !IO),
|
|
io.write_string(C2, !IO),
|
|
io.write_string(" has density ", !IO),
|
|
io.write_int(D2, !IO),
|
|
io.write_string("\n", !IO)
|
|
else
|
|
io.write_string("No solutions\n", !IO)
|
|
).
|
|
|
|
:- pred query(quad::out) is nondet.
|
|
|
|
query(quad(C1, D1, C2, D2)) :-
|
|
density(C1, D1),
|
|
density(C2, D2),
|
|
D1 > D2,
|
|
T1 = 20 * D1,
|
|
T2 = 21 * D2,
|
|
T1 < T2.
|
|
|
|
:- pred density(string, int).
|
|
:- mode density(out, out) is nondet.
|
|
|
|
density(C, D) :-
|
|
pop(C, P),
|
|
area(C, A),
|
|
P100 = P * 100,
|
|
D = P100 // A.
|
|
|
|
:- pred pop(string::out, int::out) is multi.
|
|
|
|
% populations in 100000s
|
|
pop("china", 8250).
|
|
pop("india", 5863).
|
|
pop("ussr", 2521).
|
|
pop("usa", 2119).
|
|
pop("indonesia", 1276).
|
|
pop("japan", 1097).
|
|
pop("brazil", 1042).
|
|
pop("bangladesh", 750).
|
|
pop("pakistan", 682).
|
|
pop("w_germany", 620).
|
|
pop("nigeria", 613).
|
|
pop("mexico", 581).
|
|
pop("uk", 559).
|
|
pop("italy", 554).
|
|
pop("france", 525).
|
|
pop("philippines", 415).
|
|
pop("thailand", 410).
|
|
pop("turkey", 383).
|
|
pop("egypt", 364).
|
|
pop("spain", 352).
|
|
pop("poland", 337).
|
|
pop("s_korea", 335).
|
|
pop("iran", 320).
|
|
pop("ethiopia", 272).
|
|
pop("argentina", 251).
|
|
|
|
:- pred area(string::in, int::out) is semidet.
|
|
|
|
% areas in 1000s of square miles
|
|
area("china", 3380).
|
|
area("india", 1139).
|
|
area("ussr", 8708).
|
|
area("usa", 3609).
|
|
area("indonesia", 570).
|
|
area("japan", 148).
|
|
area("brazil", 3288).
|
|
area("bangladesh", 55).
|
|
area("pakistan", 311).
|
|
area("w_germany", 96).
|
|
area("nigeria", 373).
|
|
area("mexico", 764).
|
|
area("uk", 86).
|
|
area("italy", 116).
|
|
area("france", 213).
|
|
area("philippines", 90).
|
|
area("thailand", 200).
|
|
area("turkey", 296).
|
|
area("egypt", 386).
|
|
area("spain", 190).
|
|
area("poland", 121).
|
|
area("s_korea", 37).
|
|
area("iran", 628).
|
|
area("ethiopia", 350).
|
|
area("argentina", 1080).
|