mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-25 06:14:18 +00:00
Estimated hours taken: 0.1 Add the DPPD (dozens of problems in partial deduction) suite to the tests directory.
34 lines
576 B
Mathematica
34 lines
576 B
Mathematica
|
|
:- module applast_impl.
|
|
|
|
:- interface.
|
|
|
|
:- import_module list.
|
|
|
|
:- pred applast(list(T), T, T) is semidet.
|
|
:- mode applast(in, in, in) is semidet.
|
|
:- mode applast(in, in, out) is semidet.
|
|
%:- mode applast(in, out, in) is semidet.
|
|
|
|
:- implementation.
|
|
|
|
applast(L,X,Last) :- app(L,[X],LX),list_last(Last,LX).
|
|
|
|
:- pred list_last(T, list(T)).
|
|
:- mode list_last(out, in) is semidet.
|
|
|
|
list_last(X,[H|T]) :-
|
|
(
|
|
T = [],
|
|
X = H
|
|
;
|
|
T = [_|_],
|
|
list_last(X,T)
|
|
).
|
|
|
|
:- pred app(list(T)::in, list(T)::in, list(T)::out) is det.
|
|
|
|
app([],L,L).
|
|
app([H|L1],L2,[H|L3]) :- app(L1,L2,L3).
|
|
|