[mercury-users] Debug messages
Ralph Becket
rafe at cs.mu.OZ.AU
Fri Feb 18 12:59:58 AEDT 2005
Philippe Teuwen, Thursday, 17 February 2005:
> > how can I make my program output some trace-data without using the
> > io_state?
>
> This was discussed last month.
> Check in the archives of January
> for the thread "Paper on Mercury from AI practitioner's standpoint":
> http://www.cs.mu.oz.au/research/mercury/mailing-lists/mercury-users/mercury-users.200501/index.html
>
> Especially Ralph Becket's mail with an "unsafe.m" file, very easy to use,
And here it is again:
%------------------------------------------------------------------------------%
% unsafe.m
% Ralph Becket <rafe at cs.mu.oz.au>
% Wed Jan 30 11:10:10 EST 2002
% vim: ft=mercury ff=unix ts=4 sw=4 et tw=0 wm=0
%
% Unsafe IO.
%
%------------------------------------------------------------------------------%
:- module unsafe.
:- interface.
:- import_module io, list, string.
% Support arbitrary unsafe IO operations without the need to
% thread the IO state in. Intended largely for debugging only.
%
:- pred io(pred(io, io)).
:- mode io(pred(di, uo) is det) is det.
% Useful shortcuts for writing debugging messages.
%
:- pred format(string, list(io__poly_type)).
:- mode format(in, in) is det.
:- pred format(output_stream, string, list(io__poly_type)).
:- mode format(in, in, in) is det.
:- pred print(T).
:- mode print(in) is det.
:- pred print(output_stream, T).
:- mode print(in, in) is det.
:- pred nl is det.
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
:- implementation.
%------------------------------------------------------------------------------%
io(P) :- P(unsafe_io_state, _).
%------------------------------------------------------------------------------%
format(Fmt, Args) :- io(io__format(Fmt, Args)).
format(Stream, Fmt, Args) :- io(io__format(Stream, Fmt, Args)).
%------------------------------------------------------------------------------%
print(T) :- io(io__print(T)).
print(Stream, T) :- io(io__print(Stream, T)).
%-----------------------------------------------------------------------------%
nl :- io(io__nl).
%------------------------------------------------------------------------------%
:- func unsafe_io_state = io.
:- mode unsafe_io_state = uo is det.
:- pragma foreign_proc(
"C",
unsafe_io_state = (_IO::uo),
[will_not_call_mercury, thread_safe, promise_pure],
""
).
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list