I'm programming in Prolog and sometimes I want to get a fail but instead I get an exception, which I can't understand why should be a difference between them. If something couldn't execute that's mean that the predicate didn't succed, so it's a simple fail. Am I missing something?
Asked
Active
Viewed 387 times
1 Answers
3
A failure means that what you're trying to prove is false. An exception means that what you're trying to prove doesn't make sense (e.g. trying to compute the square root of an atom) for some reason or that you bumped into some system limitation (e.g. exhausting available memory).
But you can easily convert any exception into a failure by writing:
catch(Goal, _, fail)

Paulo Moura
- 18,373
- 3
- 23
- 33
-
Yes, I know that you can do that, but why is not a default behavior? I think is not so simple, and more when you are working with non pure First Order Logic. Mainly meta-functions or meta-operators. The functionality could raise exceptions in a way , that is because the way that the operator was implemented. Something that shouldn't work that way. – titusfx Oct 06 '15 at 13:56
-
4It would be a very bad idea to be a default behavior. E.g. it would convert any typo in your code into a failure instead of an existence error. – Paulo Moura Oct 06 '15 at 13:58