[mercury-users] Re: can one_solution/2 and unsorted_solutions/2 be det?

Bart Demoen bmd at cs.kuleuven.ac.be
Tue Oct 28 19:56:31 AEDT 1997


(my code is Prolog rather than Mercury, because it doesn't matter)

Don and I seem in favour of a predicate like once/1 that could have
been implemented in Prolog as

	once(Goal) :- Goal, !.

but doesn't need to be. I would be perfectly happy if its semantics
were rather like in

	once(Goal) :-
		findall(Goal,Goal,ListOfGoal),
		random(N),
		nth_element(N,ListOfGoal,Goal).

and at each invocation - even with the same goal - returns a different
solution. I would be happy with this semantics but not with its
implementation.

Now there is no garantee that for

	a :- once(member(X,[1,2])), once(member(Y,[1,2])), X = Y.

	?- a.

succeeds. It doesn't scare me a bit: I can already write it purely;
once/1 is just that kind of a predicate.

Another aspect of the once/1 I like, cannot be simulated in Mercury:

	a(X) :- once(member(X,[1,2])) ; once(member(X,[1,2])).

also with the random definition of once/1, the query ?- a(X).
returns the same solution twice (modulo elimination of duplicate
solutions :-) because random/1 returns the same random number in
alternative branches.

I picked up once (sic) more the pruneslides.dvi that Lee recommended.
There is a striking sentence on page 18 with different uses of once/1:

	compile(I,O) - you want any solution (this may affect
	  completeness if used other than at the top level)


One person's top level is another person's goal ...

In real life, I very often want any solution (of a restricted set
though) and fortunately it is mostly not at my top level.

Bart Demoen





More information about the users mailing list