I am trying to determine the inheritance check predicate is_a/2in Prolog, but so far all my tests have failed.
The predicate is_a(X, Y)should return true when Y is a superclass of X. For example:
object(bare).
object(mammal).
object(animal).
object(bird).
is_a(bare, mammal).
is_a(mammal, animal).
is_a(bird, animal).
is_a(X, Y):- <definition goes here>.
The definition should look like the following query returns true:
?- is_a(bare, animal).
true.
I tried to define it in an obvious way, but I was stuck in endless loops:
is_a(X, Y):- X\==Y, object(X), object(Y), object(Z), is_a(X, Z), is_a(Z, Y).
Any suggestions?
Mαzen source
share