English 中文(简体)
“NOT EXISTS”
原标题:"NOT EXISTS" in swi-prolog
  • 时间:2011-09-24 18:16:20
  •  标签:
  • prolog

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?

最佳回答

以下是我的工作成果:

no_car(W):-
   worker(W),
   + owner(W, _).

现在,这接近你们。 某件事,请can当然使用_,但不限于查询。 通常使用<代码>*进行否定,not 这里我有一 error错!

EDIT:

Ah! 在我的发言中,尽管注明日期,但必须使用<条码>而不是(scar(X),使程序发挥作用,因此无需使用第1条作为术语,而不必使用经营者。 但该手册还称,not 改为+

问题回答

暂无回答




相关问题
Prolog : Learning by example

I am trying to learn a little bit about swi-prolog (beyond the basic, useless programs). Can anyone explain (perhaps in pseudocode) what this sudoku solver and the related functions are doing? If ...

Working with lists in Prolog

First off let me state that this is part of a class exercise given as homework. But, the entire assignment is much more involved than the subject of this question. So.. I am searching through two ...

SWI-Prolog conditional statements

I m trying to write a function that will test to see if the word hello is contained in a list. If it is contained, i don t want it to say "true", i want it to say : "yes, the word hello is contained ...

prolog cut off in method

I have a question I would like to ask you something about a code snippet: insert_pq(State, [], [State]) :- !. insert_pq(State, [H|Tail], [State, H|Tail]) :- precedes(State, H). insert_pq(State, [...

Max out of values defined by prolog clauses

I know how to iterate over lists in Prolog to find the maximum, but what if each thing is a separate clause? For example if I had a bunch of felines and their ages, how would I find the oldest kitty? ...

热门标签