【问题标题】:Which meanings of "type" are used in the standard?标准中使用了“类型”的哪些含义?
【发布时间】:2014-06-03 14:11:13
【问题描述】:

在 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) 仅当 Op 是不正确的列表时,并且 type_error(atom,Op) 如果Op 是任何其他非原子。

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

【问题讨论】:

    标签: iso-prolog


    【解决方案1】:

    在 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, @987654322@, in_byte, in_character, integer, list, number, @987654323@, predicate_indicator }

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

      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

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

    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 中删除。

    【讨论】:

      猜你喜欢
      • 2011-07-19
      • 2019-12-06
      • 1970-01-01
      • 2013-01-29
      • 2012-08-09
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      相关资源
      最近更新 更多