Lets say I have a relations
And then a list of people
[Ben, James, Harry, Tom, Dick]
How can I iterate the list and check the boolean of each list element as to whether they are happy or not?
Best How To :
Well, first of all, in Prolog, if a word starts with a capital letter, it means that it is a variable. So you should be careful with that.
This is my database after the correction:
and I added a recursive rule that helps me see who is happy and who is not from a given list:
write(H),write(' is happy.'),
write(H),write(' is unhappy.'),
Here is the result:
4 ?- emotion([ben, james, harry, tom, dick]).
dick is unhappy.
tom is unhappy.
harry is happy.
james is happy.
ben is unhappy.