Suppose I have the following facts:
boy(a).
boy(b).
girl(c).
girl(d).
If I query:
?-boy(X).
I get:
X=a;
X=b.
Which query should I use using a variable to get the objects that do not comply with the rule boy(), in this case, c and d?
I am new to Prolog, so I was thinking about using
?-not(boy(X)).
But that is not correct. Im using swi-prolog. Thanks in advance for your time and help.
The problem with
not(boy(X))
is that Prolog doesn't know what the "universe of possible choices" are forX
in order to then test if they're a boy. Theboy
facts only know boys, of course.One approach is to define all people in addition to the gender. For example:
Then to check for all "non-boys" you would do:
Depending upon how you want to organize your data, you can combine gender with person:
Then query:
Or write it as a predicate:
Then query: