Prolog 为什么事实必须在序言中组合在一起?
假设我列举事实:Prolog 为什么事实必须在序言中组合在一起?,prolog,iso-prolog,Prolog,Iso Prolog,假设我列举事实: letter(a). letter(b). letter(c). ... letter(z). vowel(a). consonant(b). consonant(c). consonant(d). vowel(e). consonant(f). ... consonant(z). 如果我按“字母顺序”声明规则,我会在控制台中收到以下警告: Warning: /Users/…/prolog-example.pl:31: Clauses of vowel/1 are not
letter(a).
letter(b).
letter(c).
...
letter(z).
vowel(a).
consonant(b).
consonant(c).
consonant(d).
vowel(e).
consonant(f).
...
consonant(z).
如果我按“字母顺序”声明规则,我会在控制台中收到以下警告:
Warning: /Users/…/prolog-example.pl:31:
Clauses of vowel/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:32:
Clauses of consonant/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:35:
Clauses of vowel/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:36:
Clauses of consonant/1 are not together in the source-file
Warning: /Users/…/prolog-example.pl:51:
Clauses of vowel/1 are not together in the source-file
但如果我做了以下事情:
letter(a).
letter(b).
letter(c).
...
letter(z).
consonant(b).
consonant(c).
consonant(d).
...
consonant(z).
vowel(a).
vowel(e).
vowel(i).
vowel(o).
vowel(u).
vowel(y).
我没有收到警告。警告是仅仅是
警告还是实际错误?当谓词定义不连续时,应在其子句之前使用标准不连续/1
指令声明谓词。就你而言:
:- discontiguous([
letter/1,
vowel/,
consonant/1
]).
如果不连续谓词没有相应的uncontriguous/1
指令,则结果取决于所使用的Prolog系统。例如,SWI Prolog和YAP将打印警告,但接受所有条款。GNU序言将忽略子句。ECLiPSe将报告编译错误。如果Prolog系统没有抛出错误,通常仍会打印警告,因为谓词可能会被检测为不连续,例如,由于子句头中的简单键入错误。它们只是某些系统上的警告。这是为了防止在编写新谓词时意外地向谓词添加子句。您可以在SWI中删除这些信息(这些信息看起来像您从SWI获得的信息,而且我没有太多使用其他方言)
您可以使用样式检查/1
,也可以使用中断指令
:- discontiguous vowel/1,consonant/1,letter/1.
% alternative:
:- style_check(-discontiguous).
标准ISO/IEC 13211-1:1995的内容如下:
7.4.3条款
用户定义程序p
的所有条款应为
单个序言文本的连续读取项,除非有
指令不连续(向上)
指令指示P
in
那是序言
因此,标准要求(»应«)所有条款在默认情况下是连续的。现在依赖添加的子句的程序员或程序并不依赖标准行为。您有两个元音(A)。事实。在一些Prolog系统中,它们只是“警告”。@PauloMoura:谢谢,我现在只有SWI,而且我很久没有使用任何其他东西了,在中编辑它。