忽略SWI Prolog中未定义的事实

时间:2018-03-13 15:34:27

标签: prolog

我正在针对生成的一组事实运行查询,并且可能不存在某些事实。当发生这种情况时,SWI Prolog会出现错误,例如: Undefined procedure: 'LongIdent'/4。有没有办法让它只是让'LongIdent'/4的目标失败?

1 个答案:

答案 0 :(得分:2)

您可以使用声明为unknown(-Old, +New)的{​​{3}}更改默认行为,Old是旧当前标记,New是您使用的新标记:

?- unknown(trace,fail).
Warning: Using a non-error value for unknown in the global module
Warning: causes most of the development environment to stop working.
Warning: Please use :- dynamic or limit usage of unknown to a module.
Warning: See http://www.swi-prolog.org/howto/database.html
true.

?- a(1).
false.

但你看到警告说明这可能不是一个好主意......

如果您不知道当前/旧标志,可以使用它:

?- unknown(X,fail).
    Warning: Using a non-error value for unknown in the global module
    Warning: causes most of the development environment to stop working.
    Warning: Please use :- dynamic or limit usage of unknown to a module.
    Warning: See http://www.swi-prolog.org/howto/database.html
    X = trace.