Hello,
I'm trying to define the inheritance-check predicate is_a/2
in Prolog, but so far all my trials failed.
The is_a(X, Y)
predicate should return true whenever 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 go such that the following query will return true:
?- is_a(bare, animal).
true.
I tried to define it the obvious way, but I got stuck in infinite loops:
is_a(X, Y):- X\==Y, object(X), object(Y), object(Z), is_a(X, Z), is_a(Z, Y).
Any suggestions?