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

Jeff Thompson jeff at thefirst.org
Sat Jan 7 17:49:56 AEDT 2012


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?  This is similar to Prolog once/1?

Thank you,
- Jeff

Simplified C# output for pred test.

public static bool test_0_p_0()
{
       testMercuryPredicates.Test_0_p_0_env_0 env_ptr = new 
testMercuryPredicates.Test_0_p_0_env_0();
       try
       {
           testMercuryPredicates.test_0_p_0_2(env_ptr);
           env_ptr.succeeded = false;
       }
       catch (runtime.Commit)
       {
           env_ptr.succeeded = true;
       }
}

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