“假"和“假"有什么区别?和“不"在序言中 [英] What's the difference between "false" and "no" in Prolog

查看:112
本文介绍了“假"和“假"有什么区别?和“不"在序言中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习 Prolog 之后的书 Prolog 编程:使用 ISO 标准.在语言介绍的第 7 页,他们断言:在 Prolog 中,答案 no 用于表示 没有任何东西与问题一致.记住这一点很重要nofalse 不同".那么为什么 SWI-Prolog 使用 falsetrue 语句而不是 yesno>?

I started to learn Prolog following the book Programming in Prolog: Using the ISO Standard. At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question. It is important to remember that no is not the same as false". So why SWI-Prolog uses the falseand truestatement instead of yesor no?

推荐答案

首先,ISO 标准 (ISO/IEC 13211-1:1995) 没有定义一个顶级循环.在 1 Scope 中,它写道:

To begin with, the ISO standard (ISO/IEC 13211-1:1995) does not define a toplevel loop. In 1 Scope it reads:

注意—ISO/IEC 13211的这部分没有规定:

NOTE — This part of ISO/IEC 13211 does not specify:

...

f) Prolog 处理器的用户环境(顶级循环、调试器、库
系统、编辑器、编译器等).

f) the user environment (top level loop, debugger, library
system, editor, compiler etc.) of a Prolog processor.

传统上,查询的答案是肯定的或否定的.如果是,则显示答案替换(如果存在).

Traditionally, the answer of a query has been answered with yes or no. In case of yes, answer substitutions were shown, if present.

今天,随着答案中存在越来越多的约束,传统的顶级循环变得有点难以使用.正确答案是什么?- dif(X,a).?它不能是 yes,它可能是 ma​​ybe,它首先被 Jaffar 等人的 CLP(R).但很多时候人们想要重复使用答案.

Today, with more and more constraints present in answers, the traditional toplevel loop becomes a bit cumbersome to use. What is the correct answer to ?- dif(X,a).? It cannot be a yes, it might be a maybe,which was used first by Jaffar et al.s CLP(R). But very frequently one wants to reuse the answer.

?- dif(X,a).
dif(X,a).

?- dif(b,a).
true.

?- true.
true.

继 Prolog IV 的开创性顶层之后,SWI 的想法是生成文本作为答案,以便您可以将其粘贴回以获得完全相同的结果.通过这种方式,答案的语法在某种程度上被指定 - 它必须是有效的 Prolog 文本.

Following Prolog IV's pioneering toplevel, the idea in SWI is to produce text as an answer such that you can paste it back to get the very same result. In this manner the syntax of answers is specified to some degree - it has to be valid Prolog text.

所以如果不再有是,为什么不应该有?出于这个原因,SWI 给出了 false. 作为答案.在 SWI 之前,Prolog IV 确实响应了 false.例如,请注意 SWI 中的以下修复点:

So if there is no longer yes, why should there be no? For this reason SWI gives false. as an answer. Prior to SWI, Prolog IV did respond false. Note for example the following fixpoint in SWI:

?- true; false.
true ;
false.

因此,即使是这个微小的细节也会保留在答案中.而在 Prolog IV 中,这被折叠为 true,因为 Prolog IV 一举显示所有答案.

So even this tiny detail is retained in answers. Whereas in Prolog IV this is collapsed into true because Prolog IV shows all answers in one fell swoop.

?- true ; false.

true.

有关答案的更多信息,请查看此内容.

For more on answers, see this.

这篇关于“假"和“假"有什么区别?和“不"在序言中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆