Files
mercury/tests/general/parse_list.m
Zoltan Somogyi fbe9c21558 Fix irrelevant warnings in tests/general.
tests/general/fail_detism.m:
tests/general/liveness_2.m:
tests/general/parse_list.m:
tests/general/petdr1.m:
    Change code to avoid getting irrelevant warnings.

tests/general/Mercury.options:
    Disable warnings which cannot be avoided by code changes
    without affecting the purposes of the relevant test.

tests/general/dnf.m:
    Fix language rot

tests/general/Mmakefile:
    Reenable the dnf test case.
2025-01-09 01:54:50 +11:00

51 lines
1.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% This module, originally written by Philip Dart,
% uncovered a (second) bug in the implementation of semidet predicates
% in Mercury version 0.4.
%
:- module parse_list.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module std_util.
:- import_module string.
main(!IO) :-
P = (pred(I::in, O::out, N::out) is semidet :- one_or_two(N, I, O)),
( if meta_parse_list(P, [X, Y], [2, 1, 3], _) then
string.int_to_string(X, SX),
string.int_to_string(Y, SY),
io.write_strings(["Success: X = ", SX, "; Y = ", SY, ".\n"], !IO)
else
io.write_string("Failure.\n", !IO)
).
:- pred meta_parse_list(pred(Y, Y, X), list(X), Y, Y).
:- mode meta_parse_list(pred(in, out, out) is semidet, out, in, out) is det.
meta_parse_list(P, L, In, Out) :-
( if call(P, In, Out0, E) then
L = [E | L1],
meta_parse_list(P, L1, Out0, Out)
else
L = [], Out = In
).
:- pred one_or_two(int::out, list(int)::in, list(int)::out) is semidet.
one_or_two(1) --> [1].
one_or_two(2) --> [2].