I m stuck on a simple problem in prolog. Let s consider the program
worker(bill).
worker(smitt).
worker(fred).
worker(dany).
worker(john).
car(bmw).
car(mazda).
car(audi).
owner(fred,mazda).
owner(dany,bmw).
owner(john,audi).
I need to add one more predicate no_car(X),that will be true if the worker X has no cars,i.e,if we input a query ?:- no_car(X). the prolog should answer
X=smitt,
X=bill,
yes
做了些什么
hascar(X):-owner(X,_).
nocar(X):- worker(X),not hascar(X).
But this approach does not work because anonimous variables are avaliable only for queries. So,i m really stuck on this. I know there are "NOT EXISTS" words in SQL which allow to express this logic in a query,but is there something similar to them in prolog?