1
votes

i have wroten a very simple prolog. I compiled it in swi-prolog and consult a very simple question. Here is my prolog.

isa(bird, animal).
isa(robin, bird).
isa(fish, animal).
isa(cod, fish).
isa(mammal, animal).
isa(lion, mammal).
isa(horse, mammal).
isa(bat, mammal).
isa(pipistrelle, bat).
isa1(X,Y) :- isa(X,Y).
isa1(X,Z) :- isa(X,Y), isa1(Y,Z).

My question is , when i run the following question;

isa(pipistrelle, O).

swi-prolog shows only the following ;

O = bat.

I want to display all possibilities like :

O = bat;
O = mammal;
O = animal

Could you help me at this point , thanks.

1
My mistake , i should had to run isa1(pipistrelle,O) question and put ; after for each answer.erkan çipil

1 Answers

1
votes

You're calling the isa/2 predicate but you should be calling instead the isa1/2 predicate, which is the one implementing the transitive closure for the isa relation:

?- isa1(pipistrelle, O).
O = bat ;
O = mammal ;
O = animal ;
false.