[m-users.] How do you go about logging?
olegsivokon at gmail.com
Sun Apr 6 17:04:20 AEST 2014
Thanks for reply!
Would you be so kind as to point me to the docs where I should read on
what "trailed" means?
Other then that: do I understand it correctly that "ground" in this
context means something roughly equivalent to C++ constexpr? I.e.
something that doesn't require calling functions to be computed. If
so, is there a way for the programmer to promise to the compiler that
this is the kind of variable it is? And if this is not the way it
works, then where could I read about this mechanism?
I've so far only red the book.pdf downloadable from the documentation
section of the site, but I see that it's far from being enough for
even simple stuff :)
On Sun, Apr 6, 2014 at 9:38 AM, Julien Fischer <jfischer at opturion.com> wrote:
> 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
>> % 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