For my assignment, I am supposed to list 20 potential pets and then define facts about each of the pets. Then I need to ask the potential pet owner five questions that will help decide which pets would be good recommendations. I am trying to return a list of pets based on the user input but it just returns true everytime and doesn't actually list out the recommended pets. Not sure where I am going wrong. I am only going to include some of the pets in my code example so its not terribly long.
pet_advisor.pl:
pet(cat).
pet(chameleon).
pet(chicken).
pet(chinchilla).
pet(cow).
size(cat, small).
sleeps(cat, night).
stays(cat, indoor).
stays(cat, outdoor).
class(cat, mammal).
live(cat, 12)
size(chameleon, small).
sleeps(chameleon, night).
stays(chameleon, indoor).
class(chameleon, reptile).
live(chameleon,5).
size(chicken, small).
sleeps(chicken, night).
stays(chicken, outdoor).
class(chicken, bird).
live(chicken,10).
size(chinchilla, small).
sleeps(chinchilla, day).
stays(chinchilla, indoor).
class(chinchilla, mammal).
live(chinchilla,15).
size(cow, large).
sleeps(cow, night).
stays(cow, outdoor).
class(cow, mammal).
live(cow,22).
pet_size_ok(X) :- pet_size(X), size(Y, X).
sleep_type_ok(X) :- sleep_type(X), sleeps(Y, X).
pet_location_ok(X) :- pet_location(X), stays(Y, X).
kind_ok(X) :- kind(X), class(Y, X).
life_ok(X) :- life(X), live(Y, Z), Z =< X.
which_pet(X) :- pet_size_ok(X), sleep_type_ok(X), pet_location_ok(X), kind_ok(X), life_ok(X).
recommend :- write('Do you want a small, medium, or large sized pet? '), read(Size), nl, assert(pet_size(Size)),
write('Do you want a pet that sleeps during the day or night? '), read(Sleep), nl, assert(sleep_type(Sleep)),
write('Do you want an indoor or outdoor pet? '), read(Place), nl, assert(pet_location(Place)),
write('Do you want a reptile, mammal, bird, or a fish? '), read(Type), nl, assert(kind(Type)),
write('How long do you want your pet to live (years)? '), read(Age), nl, assert(life(Age)),
findall(Pets, which_pet(Pets), Suggestions),
write('I would recommend these pets for you: '), nl, writelist(Suggestions),
retract(pet_size(Size)), retract(sleep_type(Sleep)),
retract(pet_location(Place)),
retract(kind(Type)), retract(life(Age)).
writelist([]).
writelist([H|T]) :- writeonce(H,T), writelist(T).
writeonce(H,T) :- member(H,T).
writeonce(H,T) :- not(member(H,T)), write(H), nl.
So if I were to answer the questions like: small night indoor mammal 15
It should return a list with [cat, chinchilla], but all it returns is true.