[m-users.] How do you go about logging?
jfischer at opturion.com
Sun Apr 6 16:38:17 AEST 2014
On Sun, 6 Apr 2014, Left Right wrote:
> Thanks for reply! But wouldn't you mind elaborating a bit? Here's what
> I've tried, with the error message that resulted:
> % e3.m:011: Error: trailed mutable in non-trailing grade.
Mutables are trailed by default, so if you want an untrailed mutable,
as here, it needs to be declared with the ``untrailed'' attribute, for
:- mutable(logging_level, int, 0, ground, [untrailed]).
> % e3.m:018: In clause for `nonedivides(in, out)':
> % e3.m:018: in argument 2 of call to predicate `io.write_string'/3:
> % e3.m:018: unique-mode error: the called procedure would clobber
> its argument,
> % e3.m:018: but variable `STATE_VARIABLE_IO_9' is still live.
> % e3.m:020: The goal could not be reordered, because it was followed by an
> % e3.m:020: impure goal.
> % e3.m:016: This is the location of the impure goal.
Ugh! That's all very mysterious. What the compiler is trying to
complain about there is the fact the variable ``Factor'' has inst free
in the call to io.write/3. Since the first argument of io.write/3 has
mode ``in'', it needs to ground.
I think the second mode in the declaration of nonedevices/2 is wrong,
it should be ``in'' not ``out''.
> :- mutable(logging_level, int, 0, ground, ).
> :- pred nonedivides(int::in, list(int)::out) is semidet.
> nonedivides(_, ).
> nonedivides(Test, [Factor | Factors]):-
> trace [io(!IO), state(logging_level, !LoggingLevel)]
> (!.LoggingLevel > 1 ->
> io.write_string("Factor = ", !IO),
> io.write(Factor, !IO),
> io.nl(!IO) ; true),
> Factor mod Test \= 0, nonedivides(Test, Factors).
More information about the users