What I want is when I define:
marriedTo(martin, annie).
It also makes the following true:
marriedTo(annie, martin).
I have tried the following, but it's (obviously) an infinite loop.
marriedTo(X,Y) :- marriedTo(Y,X).
How would I do this in Prolog?
The most simple way to solve it is:
marriedTo(martin, annie).
...
married(X,Y) :- marriedTo(X,Y).
married(X,Y) :- marriedTo(Y,X).
Then there are plenty of other ways, implementations and semantics that came up to solve the problem of infinite recursion...
毕竟我想通了:
marriedTo(X,Y) :- marriedTo(Y,Z), X = Z, !.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.