mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-24 13:53:54 +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.
61 lines
1.6 KiB
Mathematica
61 lines
1.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: higher_order.m.
|
|
% Author: fjh.
|
|
%
|
|
% Some very basic tests of higher-order predicates and lambda expressions.
|
|
|
|
:- module higher_order.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
:- pred map(pred(T1, T2), list(T1), list(T2)).
|
|
:- mode map(pred(in, out) is det, in, out) is det.
|
|
:- mode map(pred(in, in) is semidet, in, in) is semidet.
|
|
|
|
higher_order__map(_Pred, [], []).
|
|
higher_order__map(Pred, [X | Xs], [Y | Ys]) :-
|
|
call(Pred, X, Y),
|
|
higher_order__map(Pred, Xs, Ys).
|
|
|
|
:- pred double(string::in, string::out) is det.
|
|
double(X, Y) :-
|
|
string__append(X, X, Y).
|
|
|
|
main -->
|
|
{ higher_order__map(double, ["foo", "bar"], List) },
|
|
io__write_strings(List),
|
|
io__write_string("\n"),
|
|
(
|
|
{ higher_order__map((pred(X::in, Y::in) is semidet :-
|
|
double(X, Y)), ["ab"], ["abab"]) }
|
|
->
|
|
io__write_string("Yes\n")
|
|
;
|
|
io__write_string("Oops\n")
|
|
),
|
|
(
|
|
{ higher_order__map((pred(X::in, Y::in) is semidet :-
|
|
double(X, Y)), ["ab"], ["abracadabra"]) }
|
|
->
|
|
io__write_string("Oops\n")
|
|
;
|
|
io__write_string("No\n")
|
|
),
|
|
(
|
|
{ higher_order__map((pred(X::in, Y::in) is semidet :-
|
|
double(X, Y)), ["ab"], []) }
|
|
->
|
|
io__write_string("Oops\n")
|
|
;
|
|
io__write_string("No\n")
|
|
).
|