序言分离 [英] Prolog disjunction

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

问题描述

考虑这个 Prolog 谓词:

Consider this Prolog predicate:

silly:-
    1 = 1.
silly:-
    1 = 2.

查询时,输出的答案有两种状态:真和假.无论如何,是否可以要求 Prolog 在析取中遇到真语句时立即终止?

When querying, the output answer has two states: true and then false. Is there anyway to ask Prolog to terminate as soon as it hits a true statement in a disjunction?

推荐答案

添加剪辑

silly:-
    1 = 1, !.
silly:-
    1 = 2.

或使用 if/then/else,但是程序"的形状非常不同,将替代分支合并为单个子句.另请注意,如文档中所述

or use if/then/else, but then the 'program' take a very different shape, being the alternative branches merged into a single clause. Also note that, as stated in documentation

与 !/0 不同,谓词的选择点作为一个整体(由于多个子句)不会被破坏.

Unlike !/0, the choice point of the predicate as a whole (due to multiple clauses) is not destroyed.

silly:-
    ( 1 = 1 -> true ; false ).

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

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