mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
library/ra_list.m:
As above.
Rename ra_list_lookup to ra_list_search, since it fails if the item
to be accessed does not exist. Add a version, ra_list_lookup, which
aborts in that case.
Add predicates to append two ra_lists, and to convert ra_lists
to just plain lists.
Change the argument order of some predicates to be more
state variable friendly.
Add some documentation.
library/bt_array.m:
Delete the moved code, and update the references to the changed predicates.
library/Mercury.options:
Now that the ra_list predicates have been moved to their own module,
stop giving bt_array.m a free pass on inconsistent predicate order.
library/MODULES_DOC:
library/library.m:
Add ra_list.m as a documented module of the Mercury standard library.
library/array.m:
Delete a predicate that served as a test for an ancient bug fix.
NEWS:
Announce both the new ra_list module, and the deletion of the predicate
from array.m.
tests/hard_coded/array_sort.m:
Don't call the predicate deleted from array.m.
tests/hard_coded/ra_list_test.{m,exp}:
A new test case to test operations on ra_lists.
tests/hard_coded/Mmakefile:
Enable the new test case.
59 lines
1.4 KiB
Mathematica
59 lines
1.4 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module array_sort.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module array.
|
|
:- import_module list.
|
|
:- import_module solutions.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
unsorted_aggregate(generate, test, !IO),
|
|
io.write_string("done.\n", !IO).
|
|
|
|
:- pred generate(list(int)::out) is multi.
|
|
|
|
generate(L) :-
|
|
L0 = [0, 0, 1, 1, 2, 2, 3, 3],
|
|
sub(L0, L1),
|
|
list.perm(L1, L).
|
|
|
|
:- pred sub(list(T)::in, list(T)::out) is multi.
|
|
|
|
sub([], []).
|
|
sub([_ | T], L) :-
|
|
sub(T, L).
|
|
sub([H | T], [H | L]) :-
|
|
sub(T, L).
|
|
|
|
:- pred test(list(int)::in, io::di, io::uo) is det.
|
|
|
|
test(L, !IO) :-
|
|
list.sort(L, LS),
|
|
AS = to_list(array.sort(from_list(L))),
|
|
( if LS = AS then
|
|
% io.write_string("ok: ", !IO),
|
|
% io.write(L, !IO),
|
|
% io.nl(!IO)
|
|
true
|
|
else
|
|
io.write_string("failed: ", !IO),
|
|
io.write(L, !IO),
|
|
io.write_string(" -> ", !IO),
|
|
io.write(AS, !IO),
|
|
io.nl(!IO)
|
|
).
|