简体   繁体   中英

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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