I’m new to Prolog.
Using this basic ‘database’ structure, I thought I would be able to query the database to find out
- who eats fish?
-
what do Whales eat?
eats(Horse, grass). eats(Monkey, banana). eats(Whale, fish).
I’d like to not change that database setup (if possible). I was using the following queries with the respective unwanted results:
Here, I was trying to ask, ‘who eats fish?’
?- eats(X, fish).
true.
Here, I was trying to ask, ‘what do whales eat?’
?- eats(Whale,X).
X = grass ;
X = banana ;
X = fish.
Your queries are correct, it’s your fact database which is wrong. Atoms need to start with a lowercase letter (or be quoted). You started Horse, Monkey, Whale with uppercase letters, so they are variables (and match anything). Hence your current database is equivalent to: