[mercury-users] Using exceptions without cc_multi

Ralph Becket rafe at cs.mu.OZ.AU
Wed Aug 27 09:23:47 AEST 2003


api at gmx.de, Tuesday, 26 August 2003:
> 
> Hello mercury users!
> 
> When using try and throw in mercury, I did not find a way to use a try
> block within an ordinary clause, say, of a predicate with determinism
> declaration semidet instead of cc_multi. So something like
> 
> :- module tst_except.
> 
> :- implementation.
> :- import_module exception.
> 
> :- pred q(string::in,string::out) is semidet.
> 
> :- pred p(string,string).
> :- mode p(in, out) is semidet.
> p(A,B) :-
>    try(q(A),  Result),
>    (Result = succeeded(B)
>     ;
>     Result = exception(E),
>     %% handle E
>     fail
>    ).

What you need in this case is to change

	try(q(A), Result)

to

	Result = promise_only_solution(try(q(A)))

But make sure that calling promise_only_solution is semantically sound
or the compiler may do some strange things to your program.

promise_only_solution is a Mercury built-in function.

-- Ralph
--------------------------------------------------------------------------
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