Hi,
The commented code worked fine. I expanded it to trap runtime errors using a try/catch block and was surprised when the compiler complained that The predicate 'main::run/0', which is declared as 'procedure', is actually 'multi'. It is as if the try/catch block effectively removed the first cut so that I had to add the second one at the end to clear the error. Is this by design? If so, what is the logic behind this behavior?
implement main
open core
clauses/*
run() :-
try_test(2),!,
console::write("ok").
run() :-
console::write("fail").
*/
run():-try
try_test(2),!,%This cut has now been rendered useless
console::write("ok")catch_do
stdio::write("error")end try,!. %This cut was added to clear the compiler error.
run():-
console::write("fail").
classpredicates
try_test:(integer)determ.
clauses
try_test(X):-X>0.
end implement main
goal
console::runUtf8(main::run),
console::readchar()=_.
First Body is evaluated. If Body fails or succeeds the whole try construction fails or succeeds, respectively. I.e. if Body does not terminate with an exception the try construction corresponds to evaluating Body.
So, your code reduces to this in the absence of an exception: