How to define a relative rule in Prolog?
This is what I got so far:
spouce(X,Y) :-
wife(X,Y).
spouce(X,Y) :-
husband(X,Y).
relative-by-blood(X,Y) :-
ancestor(Z,X),
ancestor(Z,Y).
relative(X,Y) :-
relative-by-blood(X,Y).
relative(X,Y) :-
spouce(X,Y).
relative(X,Y) :-
relative-by-blood(X,Z), %<- not sure what to do here.
Thanks in advance!
Well, for starters, I think you need to rewrite relative(X,Y)
as:
relative(X,Y) :- relative-by-blood(X,Y) ; spouce(X,Y).
From there we need more info (I'll edit to add to my answer if we get more). Also, can you give us your ancestor
rules?
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.