“Not equal” sign in Visual Prolog?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 07:43:25

问题


I can't find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem:

class predicates
        sister : (string Person, string Sister) nondeterm(o,o).
    clauses
        sister(Person, Sister) :-
            Person [not-equal-sign] Sister,
            parent(Person, Parent),
            parent(Sister, Parent),
            woman(Sister).

回答1:


I don't know what do you mean by "not equal" (does not unify?), but you could try these:

X \= Y
not(X = Y)
\+ (X = Y)



回答2:


Documentation for the second variant pointed out by Kaarel can be found in this Visual Prolog reference page.

However the problem with your code goes a little deeper. You need to wait for testing of non-equality until both terms Person and Sister are bound, so rearrange things like this:

    sister(Person, Sister) :-
        parent(Person, Parent),
        parent(Sister, Parent),
        not(Person = Sister),
        woman(Sister).

There is also syntax for an infix operator "<>" which means distinct (or different). Once the two terms are bound this should give the same result as checking whether the terms cannot be unified, which is what the above construction does.



来源:https://stackoverflow.com/questions/7485212/not-equal-sign-in-visual-prolog

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