[mercury-users] Loop Checking

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Oct 29 16:31:22 AEST 1999


On 29-Oct-1999, Richard Hagen <richard at it.uq.edu.au> wrote:
> In message <19991029010341.A1935 at murlibobo.cs.mu.OZ.AU>, Fergus Henderson
> writes:
> >On 28-Oct-1999, Richard Hagen <richard at it.uq.edu.au> wrote:
> >I suspect that there is a good chance that `pragma loop_check' does
> >not do exactly what you want.  But have a look at the documentation
> >and/or try it out and let us know whether it satisfies your requirements.
> 
> The goal has got extra baggage (alas) that makes pragma loop_check
> inapplicable. An goal of the form g(X) is compiled
> into a form like 
> 	compiled_g(X, PositiveAncestores, NegativeAncestors, ...)
> In a Prolog system, you'd do the loop check by a variation on member/2
> that uses (==) rather than unification as its test of equality. e.g.

You can do the same kind of thing in Mercury by passing around a ground
representation of the ancestor goals (e.g. using the `term' type in the
standard library module `term', or some type specific to your application)
and then just using the ordinary list__member/2.

> 	identical_member(g(X), PositiveAncestors) -> !, fail

You can use if-then-else rather than cut, of course.

> Now, it might be nice if there was some way to say
> 	:- pragma loop_check(Name/Arity, ArgumentList).
> However, I'd be worried about the runtime error
> mentioned in the pragma loop_check documentation. Would it be reasonable
> and safe to replace this with an exception

Yes.  In fact `pragma loop_check' handles loops by calling error/1,
which in recent development versions now throws an exception,
so it has already been done.  It's just that the documentation was
a bit stale.  I've updated it to say that it throws an exception.

> (or, better, failure)?

That would change the program's semantics.
For that, you want the `pragma minimal_model' declaration
(which is documented in the same section as `pragma loop_check').
However, implementing that turned out to be a bit tricker that we
first thought; as it says in the documentation, our current
implementation of `pragma minimal_model' is buggy and should not be used.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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