在 ISO/IEC 13211-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)决定。
-
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, @987654322@, in_byte, in_character, integer, list, number, @987654323@, predicate_indicator }
-
模板和模式子条款中使用的类型:
8.1.2.1 参数类型
每个参数的类型由以下原子之一定义:
atom, <strong>atom_or_atom_list</strong>, atomic, byte, <strong>callable_term</strong>, character, character_code, <strong>character_code_list</strong>, character_list, clause, @987654324@, compound_term, evaluable, flag, head, in_byte, in_character, <strong>in_character_code</strong>, integer, <strong>io_mode</strong>, list, nonvar, number, operator_specifier, predicate_indicator, read_options_list, source_sink, stream, @987654325@, stream_or_alias, stream_position, stream_property, term, <strong>write_options_list</strong>
以上引用仅提到了 7.12.2 和 8.1.2.1 以及它们之间的关系。所以这需要更多的阐述:
7.12.2 的类型报告有类型错误。但是 8.1.2.1 中的类型仅在 definition of a built-in 的模板和模式子条款中提供服务。它们本身不适合用于错误。在具体的definition of a built-in predicate 中,有一个子条款 x.y.z.2 模板和模式 和 x.y.z.3 错误。以下是 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) Options 列表中的元素 E 既不是 a
变量也不是有效的写选项
— domain_error(write_option, E).
atom_or_atom_list
这更加复杂。一方面,原子列表是预期的,但原子也可以。所以我们有 list 和 atom 作为相关类型:
8.14.3.2 模板和模式
op(+integer, +operator_specifier, @atom_or_atom_list)
8.14.3.3 错误
...
f) Operator 既不是部分列表,也不是列表,也不是
一个
原子
— type_error(list, Operator).
g) Operator 列表中的元素 E 既不是
变量也不是
一个原子
— type_error(atom, E).
为错误 f 生成 atom 同样合理。另一方面,这两个错误同样适用,list 绝对是最适合像[a|nonlist] 这样的格式错误的列表,而atom 不一定更适合111,这可能是[l] 的OCR 错误。
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 中删除。