How to negate in Prolog

一世执手 提交于 2020-06-11 18:18:14

问题


I'm new to PROLOG and am at the very beginning of the exercises on this page. Given the rules parent(X, Y) and male(X), I'm trying to define a rule mother(X, Y) as

mother(X, Y) :-
    not(male(X)),
    parent(X, Y).

However, in GNU Prolog I get the following error:

| ?- mother(lina, julia).
uncaught exception: error(existence_error(procedure,not/1),mother/2)
| ?- 

回答1:


\+/1 is the ISO Prolog predicate to "negate". Note that "negate" means here not provable at that point.

You can refer to this excellent answer by @false for more on the subject




回答2:


The solution is actually in the exercise file on that page:

female(X) :- \+ male(X).

As @Mog said, negation is the unary \+ operator.



来源:https://stackoverflow.com/questions/10141600/how-to-negate-in-prolog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!