11

在 Prolog 的 ISO 标准的第一部分 ISO/IEC 13211-1:1995 中,“类型”的概念用于指代不同的事物。这常常导致混乱。例如,一个名为 IsoErrata ( archived version , source ) 的页面指出(注意此页面与 ISO 无关):

7.12.2 和 8.1.2.1

关于什么是“类型”存在混淆。似乎有3个不同的组:

  • 那些在 8.1.2.1 中列出并且也在 7.12.2.b 中的 type_error 术语中作为 ValidTypes 出现的那些
  • 那些在 8.1.2.1 中列出并在 7.12.2.c 中的 domain_error 术语中作为 ValidDomain 出现的那些
  • 仅在 8.1.2.1 中列出的那些

此外,7.12.2.c 中还有 ValidDomains 没有在 8.1.2.1 中列出,可能是错误的(例如 io_mode)。

8.14.3.3.f

模板需要atom_or_atom_list第三个参数的类型,但奇怪的是这里所需的错误术语是 type_error(list,Operator). 这导致(参见示例)

op(30,xfy,0) =====> error(type_error(list,0))

在哪里type_error(atom,0)type_error(atom_or_atom_list,0)会更合适(但请注意,atom_or_atom_list它不在 7.12.2 中列出的 ValidTypes 中!)。因此,对于 ECLiPSe,我们 type_error(list,Op)只选择了 ifOp是一个不正确的列表,并且 type_error(atom,Op)ifOp是任何其他非原子。

那么“类型”在哪些含义中使用,以及如何处理上述混淆?

4

1 回答 1

9

ISO/IEC 13211-1 中的“类型”基本上有三种不同的用途:

  1. 7.1 类型中定义的类型。它们是:变量 (7.1.1)、整数 (7.1.2)、浮点 (7.1.3)、原子 (7.1.4)、复合项 (7.1.5) 以及一些基于它们的类型。接下来的两个用法通常会参考 7.1 或术语(3 个定义)来进行定义。重要的是,这里包含了变量。这种分类是由 Prolog 的语法推动的:

    7.1 类型

    任何术语的类型由其抽象语法(6.1.2)决定。

  2. 7.12.2 b 中定义的类型。这些是在格式为 的类型错误中使用的类型type_error(ValidType, Culprit)。请注意,变量现在不再包括在内,因为这些变量要么被表示为实例化错误(7.12.2 a)或非实例化错误(7.12.2 k,Cor.2)。

ValidType∈ { }atom, atomic, byte, callable, character, compound, evaluable, float, in_byte, in_character, integer, list, number, pair, predicate_indicator

  1. 模板和模式子条款中使用的类型:

    8.1.2.1 参数的类型

    每个参数的类型由以下原子之一定义: atom, atom_or_atom_list, atomic, byte, callable_term, character, character_code, character_code_list, character_list, clause, close_options_list, compound_term, evaluable, flag, head, in_byte, in_character, in_character_code, integer, io_mode, list, nonvar, number, operator_specifier, predicate_indicator, read_options_list, source_sink, stream, stream_options_list, stream_or_alias, stream_position, stream_property, term, write_options_list

上面的引用只提到了 7.12.2 和 8.1.2.1 以及它们之间的关系。所以这需要更多的阐述:

7.12.2 的类型报告有类型错误。但是 8.1.2.1 中的类型仅在内置的定义的模板和模式子条款中提供服务。它们本身不适合用于错误。在内置谓词的具体定义中,有一个子条款xyz2 模板和模式以及xyz3 错误。以下是 8.1.2.1 类型的一些示例(上面列表中的粗体)。

write_options_list

write_options_list与错误中使用的具体类型之间没有直接的一一对应关系。相反,使用了类型list和域write_option。所以复杂类型write_options_list永远不会发出信号:

8.14.2.2 模板和模式

write_term(@stream_or_alias, @term, @write_options_list)

8.14.2.3 错误

...

c)Options既不是部分列表也不是列表
——type_error(list, Options).

...

e) 列表中的一个元素E既不Options
变量也不是有效的写选项
——domain_error(write_option, E).

atom_or_atom_list

这更加复杂。一方面,原子列表是预期的,但原子也可以。所以我们有listatom作为相关类型:

8.14.3.2 模板和模式

op(+integer, +operator_specifier, @atom_or_atom_list)

8.14.3.3 错误

...

f)Operator既不是部分列表,也不是列表,也不是
原子
——type_error(list, Operator).

g) 列表中的元素E既不Operator
变量也不是原子
——type_error(atom, E).

产生atom误差 f 同样合理。另一方面,这两个错误同样适用,并且list对于格式错误的列表(例如 )绝对是最好的[a|nonlist],而对于可能是 的 OCR 错误atom不一定更好。111[l]

callable_term

相应的类型错误包含callable. 像

8.10.1.2 模板和模式

findall(?term, +callable_term, ?list)

8.10.1.3 错误

...

b) 目标既不是变量也不是可调用的术语
—— type_error(callable, Goal)

in_character_code

7.12.2 b 中既没有对应的类型,7.12.2 c 中也没有域。但在 7.12.2 f 中,它是为表示错误定义的:

8.12.1.2 模板和模式

...
get_code(?in_character_code)
get_code(@stream_or_alias, ?in_character_code)

8.12.1.3 错误

...

j)Code是整数,但不是字符内代码
(7.1.2.2)

representation_error(in_character_code).

io_mode

这在 8.1.2.1列出,与引用的文本相反。它也出现在 7.12.2 c 中并用于:

8.11.5.3 错误

...

h)Mode是原子但不是输入/输出模式
domain_error(io_mode, Mode).

character_code_list

类似于write_options_list。但是,它在 7.12.2 c 中被错误地提及。这是Cor.3:2017中删除的标准中的错误。

于 2014-06-03T14:11:13.187 回答