GNU Prolog 断言错误 [英] GNU Prolog assert error

查看:20
本文介绍了GNU Prolog 断言错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Prolog 的新手,但我被这个看似简单的命令所困.我已经加载一个没有错误的知识库,每当我尝试做 assert(甚至是 help)我收到以下消息:

I am new to Prolog, but I am stuck at this supposedly simple command. I have loaded a knowledge base with no errors, and whenever I try do assert (and even help) I get the following message:

uncaught exception: error(existence_error(procedure,assert/1),top_level/0)
{2}

我到底错过了什么?赞赏.

What am I exactly missing? Appreciated.

推荐答案

使用 assertz/1asserta/1 代替.GNU-Prolog 不提供 assert/1,因为标准中只定义了 assert/1assertz/1.

Use assertz/1 or asserta/1 instead. GNU-Prolog does not provide assert/1 because only asserta/1 and assertz/1 are defined in the standard.

请注意,虽然 asserta/1 总是有一个明确的解释含义在开头添加子句,但 assertz/1 的含义是更难解决,因为在末尾添加一个子句"并不能完全确定在声明该子句之前已调用的目标的语义.

Note that while asserta/1 always had one clear interpretation meaning add the clause at the beginning, the meaning of assertz/1 was more difficult to resolve since "add a clause at the end" does not completely determine the semantics of goals that have been invoked prior to asserting the clause.

使用 ISO-Prolog,在 assertz/1(还有 retract/1)之前调用的目标不受影响.这称为逻辑更新视图.引用标准(ISO/IEC 13211-1:1995):

With ISO-Prolog, goals that have been invoked prior to assertz/1 (but also retract/1) remain unaffected. This is known as the logical update view. To quote the standard (ISO/IEC 13211-1:1995):

7.5.4 逻辑数据库更新

由于
而导致的数据库中的任何更改执行一个目标(例如,当 a
子目标是调用 assertz/1retract/1) 将影响
只有一个激活,其执行是在之后开始的.
更改不应影响当前的任何激活
正在执行.

Any change in the database that occurs as the result of
executing a goal (for example, when the activator of a
subgoal is a call of assertz/1 or retract/1) shall affect
only an activation whose execution begins afterwards. The
change shall not affect any activation that is currently
being executed.

注意 —因此数据库在执行期间被冻结
一个目标,定义谓词的子句列表固定在
执行的时刻(见 7.7.7 e).

NOTE — Thus the database is frozen during the execution of
a goal, and the list of clauses defining a predication is fixed at
the moment of its execution (see 7.7.7 e).

请注意,在 DECsystem 10 Prolog 中,手册在 assert/1assertz/1 之间存在很大差异.在以下引自 1978 年 DECsystem 10 用户指南的引文中,术语实现定义只能表示标准中所谓的实现依赖(本质上是未定义的).

Note that in DECsystem 10 Prolog, the manual made a big difference between assert/1 and assertz/1. In the following quote from the DECsystem 10 User guide of 1978, the term implementation defined can only mean what is known in the standard as implementation dependent (meaning essentially undefined).

5.5 元逻辑

...

assert(C)

C 的当前实例被解释为子句并被添加
到当前解释程序(带有新的私有变量
替换任何未实例化的变量).新的位置
相关过程中的子句是实现定义的.
C 必须实例化为非变量.

The current instance of C is interpreted as a clause and is added
to the current interpreted program (with new private variables
replacing any uninstantiated variables). The position of the new
clause within the procedure concerned is implementation-defined.
C must be instantiated to a non-variable.

asserta(C)

assert(C) 类似,只是新子句成为第一个
有关程序的条款.

Like assert(C), except that the new clause becomes the first
clause for the procedure concerned.

assertz(C)

assert(C) 类似,只是新子句成为最后一个
有关程序的条款.

Like assert(C), except that the new clause becomes the last
clause for the procedure concerned.

今天也有 assert/1assertz/1 不同的系统.例如,.

Also today there are systems where assert/1 and assertz/1 differ. E.g., xsb.

这篇关于GNU Prolog 断言错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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