[mercury-users] Printing reference's values

Ralph Becket rafe at cs.mu.OZ.AU
Thu Dec 5 14:24:32 AEDT 2002


I can't reproduce the error you're seeing.  The attached program runs
fine and seems to do just what you describe.  Hmm...

- Ralph
-------------- next part --------------
%-----------------------------------------------------------------------------%
% foo.m
% Ralph Becket <rafe at cs.mu.oz.au>
% Thu Dec  5 14:12:54 EST 2002
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%
%-----------------------------------------------------------------------------%

:- module foo.

:- interface.

:- import_module io.



:- impure pred main(io::di, io::uo) is det.

%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%

:- implementation.

:- import_module reference, map, int, char, list, assoc_list, std_util, string.

%-----------------------------------------------------------------------------%

main(!IO) :-
    T1 = map__from_assoc_list([a - 3, b - 2, c - 1]) `with_type` map(char, int),
    impure new_reference(T1, R),
    semipure value(R, X1),
    io__write(X1, !IO),
    io__nl(!IO),
    io__write(X1, !IO),
    io__nl(!IO),
    io__format("X1 ^ elem(a) = %d\n", [i(X1 ^ det_elem(a))], !IO),
    io__format("X1 ^ elem(c) = %d\n", [i(X1 ^ det_elem(c))], !IO),
    T2 = map__from_assoc_list([a - 1, b - 2, c - 3]) `with_type` map(char, int),
    impure update(R, T2),
    semipure value(R, X2),
    io__write(X2, !IO),
    io__nl(!IO),
    io__write(X2, !IO),
    io__nl(!IO),
    io__format("X2 ^ elem(a) = %d\n", [i(X2 ^ det_elem(a))], !IO),
    io__format("X2 ^ elem(c) = %d\n", [i(X2 ^ det_elem(c))], !IO).

%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%


More information about the users mailing list