Prolog谓词无法解决

时间:2018-02-19 17:49:30

标签: list prolog prolog-findall

这可能是一个新手的错误,但我正试图解决这个问题:

使用findall谓词查找查询以获得以下答案:获取在他们居住的城市以外的城市工作的人员列表:

L = [suzy, paul].

这是数据库:

city(ottawa,ontario).
city(toronto,ontario).
city(kingston,ontario).
city(gatineau,quebec).
city(montreal,quebec).

company(shopify,ottawa).
company(rossvideo,ottawa).
company(dium,gatineau).
company(uber,toronto).
company(deepmind,montreal).
company(google,toronto).

person(annie,gatineau).
person(paul,gatineau).
person(suzy,gatineau).
person(robert,gatineau).
person(tom,ottawa).
person(tim,kingston).
person(joe,montreal).
person(jane,ottawa).
person(marie,ottawa).
person(jack,toronto).
person(simon,toronto).

employee(annie,dium).
employee(tom,shopify).
employee(jane,shopify).
employee(marie,shopify).
employee(joe,deepmind).
employee(jack,google).
employee(simon,google).
employee(suzy,shopify).
employee(paul,rossvideo).
employee(marie,rossvideo).
employee(simon,uber).

这是我试图用来解决它的谓词:

worksIn(n, Y) :-
   employee(n, Comp),
   company(Comp, Y).

但它只返回false。有谁知道如何解决它?

2 个答案:

答案 0 :(得分:0)

我做了:

worksIn(P):- person(P,CL), employee(P, CO), company(CO, CW), CL/=CW.

所以最后的答案是:

findall(P, worksIn(P), L).

我不确定我们是否可以添加“worksIn”内容

答案 1 :(得分:-1)

使用变量时,首字母必须是大写。