[m-dev.] from [mercury-users] Re: Question regarding determinism

Peter Schachte pets at cs.mu.OZ.AU
Sun Sep 13 16:32:03 AEST 1998


On Fri, Sep 11, 1998 at 06:15:23PM +1000, Andrew Bromage wrote:

> > There are other cases where making determinism analysis smarter would help.
> 
> Determinism analysis currently has the benefit of being a nice, simple
> bottom-up analysis.  I'd much prefer to keep it like that, if only to
> make it easier on the next Mercury implementation.

No reason you can't keep it reasonably simple and bottom-up and still
make it smarter.

> I think the case above is a Prolog syntax bug.  Conjunctions should nest
> as the programmer stated they'd nest rather than as Prolog parses them.

I thought conjunction was supposed to be commutative and associative?
Anyway, this parenthses-are-significant approach means that you can
take a semidet clause body and make it nondet just by adding a semidet
goal at the end.  That doesn't seem like a good outcome.

> Of course, it could be argued that the programmer should be obliged to
> write it as some [Z] (q, r) if they want a better determinism.

So you want to throw out the rule that variables are quantified in
their closest enclosing scope?  I find that quite a natural and
convenient rule.

Personally, if I wrote

	:- mode t(in, out).
	t(X, O) :-
		p(X, Y),		% outputs `Y'
		q(Y, Z),		% outputs `Z'
		r(Z),			% texts `Z'
		s(O).			% outputs `O'.

I'd kind of expect the Mercury compiler to tell that t/2 in that mode
should have the same determinism as s(out), except that it might fail.
In fact, unless I'm missing something, using the scoping rule and
determinism inference you're envisioning, the code as Fergus wrote it
would still not give the right determinism:

	t(X, O) :-
		p(X, Y),		% outputs `Y'
		( q(Y, Z), r(Z) ),	% outputs only `Z', which is local
		s(O).			% outputs `O'.

because the Mercury compiler would not infer that Y's scope ended
before the s/1 call.  You'd have to write:

	t(X, O) :-
		( p(X, Y), ( q(Y, Z), r(Z) )),
		s(O).			% outputs `O'.

which is starting to get pretty ugly.

-- 
Peter Schachte                | Bill Gates is only a white persian cat and a
mailto:pets at cs.mu.OZ.AU       | monocle away from being the villain in a
http://www.cs.mu.oz.au/~pets/ | James Bond movie.
PGP: finger pets at 128.250.37.3 |     -- Dennis Miller 



More information about the developers mailing list