开发者

"Not equal" sign in Visual Prolog?

开发者 https://www.devze.com 2023-04-06 16:32 出处:网络
I can\'t find any documentation on "not equal" sign in Visual Prolog. Please provide the right solution of this problem:

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).


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消