mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
compiler/parse_mutable.m:
compiler/parse_type_name.m:
As above.
tests/hard_coded/higher_order_mutable.{m,exp}:
A new test case for the new capability, checking whether we can call
a closure we got out of a mutable.
tests/hard_coded/Mmakefile:
Enable the new test case.
66 lines
1.5 KiB
Mathematica
66 lines
1.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module higher_order_mutable.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- mutable(numerals, (pred(int::in, string::out) is semidet), english, ground,
|
|
[untrailed, attach_to_io_state]).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
|
|
main(!IO) :-
|
|
test(1, !IO),
|
|
test(2, !IO),
|
|
test(3, !IO),
|
|
test(4, !IO),
|
|
|
|
io.nl(!IO),
|
|
set_numerals(spanish, !IO),
|
|
|
|
test(1, !IO),
|
|
test(2, !IO),
|
|
test(3, !IO),
|
|
test(4, !IO).
|
|
|
|
:- pred test(int::in, io::di, io::uo) is det.
|
|
|
|
test(N, !IO) :-
|
|
get_numerals(Numerals, !IO),
|
|
( if Numerals(N, NStr) then
|
|
io.format("numeral %d -> %s\n", [i(N), s(NStr)], !IO)
|
|
else
|
|
io.format("numeral %d is unknown\n", [i(N)], !IO)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred english(int::in, string::out) is semidet.
|
|
|
|
english(1, "one").
|
|
english(2, "two").
|
|
english(3, "three").
|
|
|
|
:- pred spanish(int::in, string::out) is semidet.
|
|
|
|
spanish(1, "una").
|
|
spanish(2, "dos").
|
|
spanish(3, "tres").
|