[m-dev.] trace goals and quantification

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Sep 26 16:54:39 AEST 2006


Trace goals and quantification seem to have a rather nasty interaction.
The following program:

 	:- module tg_bug1.
 	:- interface.
 	:- import_module io.
 	:- pred main(io::di, io::uo) is det.
 	:- implementation.

 	main(!IO) :-
 	    trace [io(!I)] (
 		io.stdout_stream(StdOut, !I),
 		io.write_string(StdOut, "In first trace goal.\n", !I)
 	    ),
 	    io.write_string("Out of first trace goal.\n", !IO),
 	    trace [io(!I)] (
 		io.stdout_stream(StdOut, !I),
 		io.write_string(StdOut, "In second trace goal.\n", !I)
 	    ).

results in:

 	Making Mercury/cs/tg_bug1.c
 	tg_bug1.m:012: In clause for `main(di, uo)':
 	tg_bug1.m:012:   in argument 1 of call to predicate
 	tg_bug1.m:012:   `private_builtin.trace_set_io_state'/1:
 	tg_bug1.m:012:   unique-mode error: the called procedure would clobber its
 	tg_bug1.m:012:   argument, but variable `STATE_VARIABLE_I_3' is still live.
 	For more information, recompile with `-E'.
 	** Error making `Mercury/cs/tg_bug1.c'.

It can be fixed by:

 	:- module tg_bug1.
 	:- interface.
 	:- import_module io.
 	:- pred main(io::di, io::uo) is det.
 	:- implementation.

 	main(!IO) :-
 	    trace [io(!I)] ( some [StdOut] (
 		io.stdout_stream(StdOut, !I),
 		io.write_string(StdOut, "In first trace goal.\n", !I)
 	    )),
 	    io.write_string("Out of first trace goal.\n", !IO),
 	    trace [io(!I)] ( some [StdOut] (
 		io.stdout_stream(StdOut, !I),
 		io.write_string(StdOut, "In second trace goal.\n", !I)
 	    )).

The fact that we need to resort to this seems to go against the whole
notion of trace goals, i.e that variables that are bound inside the
trace goal, StdOut in this case, cannot affect the rest of the program.

Julien.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list