Imagine that I have the following knowledge base, which gives each person their own name and age.
person(mary, 39).
person(john, 24).
person(sandy, 17).
Now I want to get all people over 20 years old. In addition, I just want to collect their names, not their age. Here I want to get maryand john.
How to do this usually in Prolog and more specifically in SWI-Prolog?
If we use a variable that is not anonymous, for example:
?- person(X, Y), Y > 20.
Prolog will give me values for Xand Y, and I don't want to Y.
I cannot use an anonymous variable _because Prolog cannot bind its two instances. The following is the error:
?- person(X, _), _ > 20.
So how to do this?