Try/Catch block makes the cut useless:what is the rationale?
Posted: 16 Jul 2015 17:44
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?
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?
Code: Select all
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").
class predicates
try_test:(integer) determ.
clauses
try_test(X):-X>0.
end implement main
goal
console::runUtf8(main::run),
console::readchar()=_.