[mercury-users] First solution in csharp without try/catch

Jeff Thompson jeff at thefirst.org
Tue Jan 10 18:15:13 AEDT 2012


On 1/8/2012 8:58 PM, Mark Brown wrote:
> Hi Jeff,
>
> On 06-Jan-2012, Jeff Thompson<jeff at thefirst.org>  wrote:
>> Hello again.  I'm using the csharp grade to compile the following.
>>
>> :- pred multiPred(int::out) is multi.
>> multiPred(1).
>> multiPred(2).
>>
>> :- pred test is semidet.
>> test :- if multiPred(X), X>  0 then true else fail.
>>
>> In pred test, in the if statement, when "multiPred(X), X>  0" first
>> succeeds, the predicate succeeds, else fails.  The compiled C# code works
>> correctly.  But the implementation throws a new runtime.Commit() exception
>> when it first succeeds, and catches this in an outer try/catch block (see
>> below).  I can understand why the authors would have implemented it this
>> way, but using exceptions for message passing in normal operation is very
>> inefficient.
>> Is there another way (where the implementation doesn't use try/catch) to
>> make a semidet predicate which succeeds on the first solution of some code
>> block?
> I don't think there is a more efficient solution, short of avoiding nondet
> code to begin with (i.e., implement your own search in det/semidet code).

Thanks for the feedback.  Can you say something more about the approach 
to implement my own search?

Also, solutions.do_while in the library can "stop before all solutions 
have been found".  Does it also use try/catch internally?

Thanks,
- Jeff
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list