[mercury-users] Debug prints get optimized away

Ondrej Bojar obo at cuni.cz
Tue Feb 21 03:03:55 AEDT 2006


Hi.

Is there a way to produce (impure) debugging prints so that the call is 
not optimized away?

I used to use unsafe_perform_io from the unsafe.m, I switched to a 
direct implementation recently:

:- pragma c_code(emit_string(Str::in), [will_not_call_mercury], "
   fprintf(stderr, ""%s"", Str);
").

:- func dump(T::in) = (string::out) is det.
dump(Anything) = pprint__to_string(32000, to_doc(Anything)).

:- pred debugstr(string::in, S::in) is det.

debugstr(Comment, Anything) :-
   emit_string(Comment),
   emit_string(dump(Anything)),
   emit_string("\n").

However, rotd-2006-02-18 optimizes all calls to debugstr/2 away as it is 
a deterministic predicate with no output..

I do not want to make all my code impure just to be able to every now 
and then add a debugging print. I also do not want to lead the IO wiring 
everywhere.

What trick would you recommend for this?

Thanks, O.

-- 
Ondrej Bojar (mailto:obo at cuni.cz)
http://www.cuni.cz/~obo
--------------------------------------------------------------------------
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