Files
mercury/tests/hard_coded/mutable_init_impure.m
Zoltan Somogyi 58ea6ffff2 Delete old obsolete predicates and functions.
library/*.m:
    Specifically, delete any predicates and functions whose `pragma obsolete'
    dates from 2018 or before. Keep the ones that were obsoleted
    only this year or last year.

NEWS:
    Announce the changes.

tests/debugger/io_tab_goto.m:
tests/debugger/tabled_read.m:
tests/declarative_debugger/io_stream_test.m:
tests/declarative_debugger/tabled_read_decl.m:
tests/declarative_debugger/tabled_read_decl_goto.m:
tests/general/array_test.m:
tests/hard_coded/mutable_init_impure.m:
tests/hard_coded/remove_file.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace references to predicates and functions that this diff deletes
    with their suggested replacements.

    In several test cases, bring the programming style up to date.

tests/hard_coded/shift_test.{m,exp}:
    Most of this test case tested the now-deleted legacy shift operations.
    Replace these with tests of their non-legacy versions, including
    testing for the expected exceptions.

tests/hard_coded/shift_test.{m,exp}:
    Don't pass --no-warn-obsolete when compiling shift_test.m anymore.
2020-08-18 11:57:47 +10:00

48 lines
1.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Test initialisation of mutables by impure functions.
:- module mutable_init_impure.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module thread.
:- import_module thread.semaphore.
:- mutable(sem1, semaphore, init_sem, ground, [untrailed, attach_to_io_state]).
:- mutable(sem2, semaphore, init_sem, ground, [untrailed, constant]).
:- impure func init_sem = semaphore.
init_sem = Sem :-
impure Sem = semaphore.impure_init(1).
:- mutable(foo, string, init_foo, ground, [untrailed, constant]).
:- semipure func init_foo = string.
init_foo = X :-
promise_semipure X = "Testing...".
main(!IO) :-
get_sem1(Sem1, !IO),
semaphore.wait(Sem1, !IO),
get_sem2(Sem2),
semaphore.wait(Sem2, !IO),
get_foo(Foo),
io.write_string(Foo, !IO),
io.nl(!IO),
io.write_string("Success.\n", !IO).