Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Prolog 中编程,有时我想失败,但我得到了一个异常,我不明白为什么它们之间应该有区别。如果某事无法执行,则意味着谓词没有成功,所以这是一个简单的失败。我错过了什么吗?
失败意味着你试图证明的是错误的。例外意味着您试图证明的内容由于某种原因没有意义(例如,尝试计算原子的平方根),或者您遇到了某些系统限制(例如,耗尽了可用内存)。
但是您可以通过编写以下内容轻松地将任何异常转换为失败:
catch(Goal, _, fail)