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

Jeff Thompson jeff at thefirst.org
Fri Jan 13 10:45:50 AEDT 2012


On 1/9/2012 11:15 PM, Jeff Thompson wrote:
> 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).

I'm still struggling with this one. I set pred test to the "fast 
version" which tests "X > 2" which fails and does not throw an 
exception. A benchmark with 10,000,000 calls to this takes only 0.45 
seconds. (Awesome!)

When I set the test back to "X > 0" where it throws the exception, the 
benchmark takes 171 seconds.  That's 380 times as long.  This is what 
"message passing with exceptions is inefficient" means.  It really 
hurts.  Is there no help to be gotten from the compiler?

Thanks for any help,
- 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