[mercury-users] Determinism of try/2
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Jan 25 11:02:58 AEDT 2006
On 25-Jan-2006, Mark Brown <mark at cs.mu.OZ.AU> wrote:
> On 24-Jan-2006, Peter Hawkins <hawkinsp at cs.stanford.edu> wrote:
> > Hi...
> >
> > Why does exception.try/2 have determinism cc_multi when called on a det
> > predicate? It doesn't look like a committed choice operation to me...
>
> The solutions for such a call are succeeded(R) where R is the result
> according to the declarative semantics of the det predicate, and
> exception(E) where E is any value (with type univ). Only one of these
> solutions is chosen at run time; you can't get the other ones on
> backtracking.
To expand on Mark's answer: the called closure may contain code to throw
more than one exception, and since (in the absence of compiler options
to the contrary) the compiler is free to reorder conjunctions and disjunctions,
the declaration semantics says you may get any one of these exceptions.
Operationally of course you get just one. It is this choice that the cc_multi
represents.
The workaround is trivial, and I actually had occasion to use it just
yesterday. It is to wrap promise_equivalent_solutions around the call
to try, like this:
promise_equivalent_solutions [Result] (
try(string.format(FormatString, Values), Result)
),
Zoltan.
--------------------------------------------------------------------------
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