简体   繁体   English

Prolog 谓词无法解析

[英]Prolog predicate doesn't resolve

This may be a rookie mistake, but I'm trying to solve this question:这可能是一个菜鸟错误,但我正在尝试解决这个问题:

Find the query to obtain the following answer using the findall predicate: Obtain a list of persons who work in a city other than the one where they live:使用 findall 谓词查找查询以获取以下答案:获取在其居住城市以外的城市工作的人员列表:

L = [suzy, paul].

This is the database:这是数据库:

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).

Here is the predicate I tried to use to solve it:这是我试图用来解决它的谓词:

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

But it only returns false .但它只返回false Does anyone know how to fix it?有谁知道如何修理它?

I did:我做了:

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

so the final answer is:所以最后的答案是:

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

I'm not sure if we can add the "worksIn" thing in or not我不确定我们是否可以添加“worksIn”的东西

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM