prolog - When does Prolog prompts 'yes' and when does it says 'true'
问题描述
I wrote the following knowledge base in Prolog:
likes(yamini,chocolate).
likes(anuj,apple).
likes(yamini,book).
likes(john,book).
likes(john,france).
Now, when I consult the above file and try the following commands:
| ?- likes(anuj,apple).
(1 ms) yes
| ?- likes(yamini,chocolate).
true ? ;
no
I want to understand when does Prolog replies a 'yes' versus when does it replies 'true'.
解决方案
This is an artefact of the toplevel (Prolog command line) implementation. Apparently you implementation says true
when it could prove a goal and it is unsure whether there may be more solutions. If it is sure that there is only one solution, it says yes
.
Here is what SWI-Prolog does:
?- likes(anuj,apple).
true.
Prolog could successfully prove the goal likes(anuj,apple)
and it is also sure there are no other ways to prove it otherwise one would see something like this:
?- member(X,[1,2]).
X = 1 ;
X = 2.
where an X
that makes the goal true has been found as 1
but there may be other solutions. And indeed there are, namely 2
.
Back to our example:
?- likes(yamini,chocolate).
true.
推荐阅读
- android - 为什么模拟数据返回null?
- python-3.x - 登录系统对象:“str”对象没有属性“items”
- regex - 正则表达式:由非字母包围的一组可选单词仅捕获一个单词
- python - Python/Pandas - 给定特定日期,在列表中查找上一个日期
- python - pytables 组和弱引用
- python - Django过滤下拉菜单有效选择错误
- reporting-services - 来自两个不同数据集的 SSRS COALESCE
- reactjs - 获取“JSX 元素类型‘组件’没有任何构造或调用 signatures.ts(2604)”
- jquery - 从 Javascript 调用 Controller Action 和从这个刷新站点
- python - 使用 Paramiko 库从特定路径复制所有 CSV 文件及其子目录