简体   繁体   中英

Why throw an exception in Prolog instead a simple fail?

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?

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 (eg trying to compute the square root of an atom) for some reason or that you bumped into some system limitation (eg exhausting available memory).

But you can easily convert any exception into a failure by writing:

catch(Goal, _, fail)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM